referencing $E2 in VBA

dshafique

Board Regular
Joined
Jun 19, 2017
Messages
171
Hi guys, so im having an issue figuring out something. I'm trying to write a code which changes the color of a cell depending on if its greater than or less than a different cell. as a formula, i would have done $E2, however, when i put $E2 in vba, all the cells then reference only E2, i want it to look at the cell in the corresponding row of Column E. I cant do RC- the number of columns because im working on a dynamic sheet that adds columns each month. this is what i have, if it helps

Code:
Range("TableAll[[#Headers],[Fiscal YTD]]").Select
    ActiveCell.Offset(1, 1).Select
    Range(ActiveCell, Cells(ActiveCell.End(xlDown).Row, ActiveCell.End(xlToRight).Column)).Select
    
    Dim cl As Range
    For Each cl In Range(ActiveCell, Cells(ActiveCell.End(xlDown).Row, ActiveCell.End(xlToRight).Column))
    If cl >= "" Then
       cl.Interior.Color = 5287936
    End If
    Next cl
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
What formula are you trying to use and where are you trying to use it?
 
Upvote 0
my bad guys, it seems like i accidentally deleted the condition, here it is again

Range("TableAll[[#Headers],[Fiscal YTD]]").Select
ActiveCell.Offset(1, 1).Select
Range(ActiveCell, Cells(ActiveCell.End(xlDown).Row, ActiveCell.End(xlToRight).Column)).Select

Dim cl As Range
For Each cl In Range(ActiveCell, Cells(ActiveCell.End(xlDown).Row, ActiveCell.End(xlToRight).Column))
If cl >= "$E2" Then
cl.Interior.Color = 5287936
End If
Next cl
 
Upvote 0
One more thing, how would i write it if i want it to be greater than or equal to? do i just put two equal signs?
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,334
Members
452,636
Latest member
laura12345

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