Change VBA to cover column not just one cell

wazzulu1

Board Regular
Joined
Oct 4, 2006
Messages
164
Hi;

I was trying to change this to cover entire columns, if T2 is " ", then A2 font would turn red. I have this for that specific cell, but would like to have this cover the entire columns to perform this action if possible?

Code:
Sub Pop()
If Range("T2") = "" Then
    Range("A2").Font.Color = vbRed
Else
   Range("A2").Font.Color = vbBlue
End If
End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try

Code:
Sub Pop()
Dim lr As Long, r As Long
lr = Cells(Rows.Count, "T").End(xlUp).Row
For Each cell In Range("T2:T" & lr)
If Range("T" & r) = "" Then
    Range("A" & r).Font.Color = vbRed
Else
   Range("A" & r).Font.Color = vbBlue
End If
Next r
End Sub
 
Upvote 0
Hi Michael;

I got this error message using this code:
Compile error: Invalid Next control variable reference
 
Upvote 0
See if this works for you:
Code:
Sub Pop()
    Dim rng As Range, cll As Range
    Set rng = Range("A2", Cells(Rows.Count, "A").End(xlUp))
    rng.Font.Color = vbBlue
    For Each cll In rng
        If cll.Offset(, 19) = "" Then cll.Font.Color = vbRed
    Next cll
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,891
Messages
6,122,101
Members
449,066
Latest member
Andyg666

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