SOLVED

Question related to loops

%3CLINGO-SUB%20id%3D%22lingo-sub-2441766%22%20slang%3D%22en-US%22%3EQuestion%20related%20to%20loops%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2441766%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20Everyone%2C%3C%2FP%3E%3CP%3EI%20have%20created%20code%20which%20those%20value%20greater%20than%2010%2C%20then%20it%20highlight%20red%20in%20colour.%3C%2FP%3E%3CP%3EIt%20works%20in%201st%20column%2C%20but%20not%20jump%20to%202nd%20column%20to%20highlight.%3C%2FP%3E%3CP%3Elike%20-%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Screenshot%20(3766).png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F288209i971FF01349C4C96B%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Screenshot%20(3766).png%22%20alt%3D%22Screenshot%20(3766).png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20Here%20is%20a%20code%20-%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Screenshot%20(3767).png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F288210i88A01A1ABCCC188E%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Screenshot%20(3767).png%22%20alt%3D%22Screenshot%20(3767).png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20should%20i%20write%20in%20VBA%20code%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPlease%20help..%3F%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere%20is%20a%20attach%20file..%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2441766%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2441803%22%20slang%3D%22en-US%22%3ERe%3A%20Question%20related%20to%20loops%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2441803%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F811137%22%20target%3D%22_blank%22%3E%40Zan_Hanifee%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETry%20this%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-visual%22%3E%3CCODE%3EPublic%20Sub%20FunWithLoop()%0A%20%20%20%20Dim%20cel%20As%20Range%0A%20%20%20%20Application.ScreenUpdating%20%3D%20False%0A%20%20%20%20For%20Each%20cel%20In%20ActiveSheet.UsedRange%0A%20%20%20%20%20%20%20%20If%20IsNumeric(cel.Value)%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20If%20cel.Value%20%26gt%3B%2010%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20cel.Interior.Color%20%3D%20vbRed%0A%20%20%20%20%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20Next%20cel%0A%20%20%20%20Application.ScreenUpdating%20%3D%20True%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EP.S.%20You%20can%20also%20use%20Conditional%20Formatting%20to%20highlight%20cells%20with%20a%20value%20greater%20than%2010.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2441804%22%20slang%3D%22en-US%22%3ERe%3A%20Question%20related%20to%20loops%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2441804%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F127945%22%20target%3D%22_blank%22%3E%40Hans%20Vogelaar%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESir%2C%20Can%20we%20write%20with%20the%20help%20of%20%3CSTRONG%3EActiveCell.Offset%26nbsp%3B%3C%2FSTRONG%3Ewhich%20i%20have%20written%20the%20code%3F%3F%3C%2FP%3E%3CP%3EIf%20yes%2C%3C%2FP%3E%3CP%3Ethen%20what%20should%20i%20write%3F%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E
Regular Contributor

Hello Everyone,

I have created code which those value greater than 10, then it highlight red in colour.

It works in 1st column, but not jump to 2nd column to highlight.

like - 

Screenshot (3766).png

 

And Here is a code - 

Screenshot (3767).png

 

 

What should i write in VBA code?

 

Please help..??

 

Here is a attach file..

 

4 Replies
best response confirmed by allyreckerman (Microsoft)
Solution

@Zan_Hanifee 

Try this:

Public Sub FunWithLoop()
    Dim cel As Range
    Application.ScreenUpdating = False
    For Each cel In ActiveSheet.UsedRange
        If IsNumeric(cel.Value) Then
            If cel.Value > 10 Then
               cel.Interior.Color = vbRed
            End If
        End If
    Next cel
    Application.ScreenUpdating = True
End Sub

P.S. You can also use Conditional Formatting to highlight cells with a value greater than 10.

@Hans Vogelaar 

Sir, Can we write with the help of ActiveCell.Offset which i have written the code??

If yes,

then what should i write??

@Zan_Hanifee 

Selecting cells in a macro is very inefficient! You should avoid it.

Thank you so much sir