IF THEN LOOP with ActiveCell

Vanish29

New Member
Joined
Apr 28, 2016
Messages
22
Hello,
I am trying to use an If Then Loop, but I cannot seem to get it to function properly
Final Product:
Excel will look at Column AN and if the cell value is True, then it will select the entire row and color it orange. Then it will go down to the next cell and check, until it reaches a blank cell.

Here is my current code
Code:
   Dim i As Long
   i = 1
   Do While Cells(i, "AN").Value <> ""
      If Cells(i, "AN").Value = "True" Then
           ActiveCell.EntireRow.Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 820980
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
      End If
      i = i + 1
   Loop

I think my problem may be the ActiveCell.EntireRow.Select, but I am not certain how to fix it.
I have been searching through forums and google for a while now, with this being the 15th iteration of code, to no avail.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try this:

Code:
Sub My_Sub()
'Modified 10/23/2018 5:55 PM  EDT
Application.ScreenUpdating = False
Dim r As Range
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "AN").End(xlUp).Row
For Each r In Range("AN1:AN" & Lastrow)
    If r.Value = "True" Then
    
        With r.EntireRow.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .Color = 820980
            .TintAndShade = 0
            .PatternTintAndShade = 0
        End With
    End If
Next
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
This works great.
So I was correct in thinking that the ActiveCell was causing the issues.
Thank you very much.
SOLVED
 
Upvote 0

Forum statistics

Threads
1,215,666
Messages
6,126,106
Members
449,292
Latest member
Mario BR

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top