Conditional Formatting based on another cells value VBA

Musa15

Board Regular
Joined
Mar 8, 2015
Messages
63
Hi,

Hope I can find some insight here. I am working on highlighting cells in column Y and V $Y$2:$Y$35 / $V$2:$V$35 based on formula rule on $$AA2 values. Can anyone offer guidance on how to do this on VBA? Basically, if cells in AA2 do not = 0, are greater than or less than zero then I would need the respective V and Y column to become red. When I record myself doing the conditional formatting I am unable to get the code to yield highlighted cells. Additionally, my current way of highlighting it manually highlights cells that are blank :/ any insight would be much appreciated.
Screen%20Shot%202015-03-04%20at%2010.21.27%20PM_zpspdqir2cw.png
[/URL][/IMG]
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hi,
Are you asking to get the same results as the conditional formatting but using vba code? I have copied your rules and have not found any issues with highlighting unless auto-calculation is disabled. Are you using manual calculation?
 
Upvote 0
Yes, I am trying to get the same results using VBA code. For some reason, when recording myself and playing it back I am not getting any highlighting.

I have this going on:

Sub Macro10()
'
' Macro10 Macro
'

'
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$AA2<0"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ColorIndex = xlAutomatic
End With
Selection.FormatConditions(1).StopIfTrue = False
Cells.FormatConditions.Delete
Range("AA1").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
Formula1:="=0"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ColorIndex = xlAutomatic
End With
Selection.FormatConditions(1).StopIfTrue = True
Range("Y2:Y35").Select
Range("AA1").Activate
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$AA2<0"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ColorIndex = xlAutomatic
End With
Selection.FormatConditions(1).StopIfTrue = False

End Sub
 
Last edited:
Upvote 0
Hi,
The top cell in your selection will always refer to AA2 not the same row as the selection.
 
Upvote 0
Hi,
The top cell in your selection will always refer to AA2 not the same row as the selection.

Hi,

I don't understand. What should it look like, so that it references the correct row based on value of not zero? thank you for your help btw, I'm teaching myself vba and appreciate the help on this forum.
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,687
Members
449,117
Latest member
Aaagu

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