VBA Code to highlight one cell if greater or less than another

Tryingtoresolve

New Member
Joined
Aug 28, 2023
Messages
35
Office Version
  1. 365
Platform
  1. Windows
I have been trying to change VBA code on an existing spreadsheet with macros I have managed to get the red and green VBA code to work but I can't get the Ambre code to work

What I'm looking for is when U2 is updated with a qty greater than 1 but less than the Qty shown in cell R2 the cell should turn Amber

This is the code I'm using

Range("U2:U" & LR).Select

Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=U2>=1 <=R2"

Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority

With Selection.FormatConditions(1).Interior

.PatternColorIndex = xlAutomatic

.Color = RGB(252, 213, 180) 'Amber

.TintAndShade = 0

End With

Range("U2:U" & LR).Select

Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=U2>R2"

Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority

With Selection.FormatConditions(1).Interior

.PatternColorIndex = xlAutomatic

.Color = 255 'RED

.TintAndShade = 0

End With

Range("U2:U" & LR).Select

Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=U2=R2"

Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority

With Selection.FormatConditions(1).Interior

.PatternColorIndex = xlAutomatic

.Color = RGB(216, 228, 188) 'Green

.TintAndShade = 0

End With
 

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