Conditional Formatting using VBA for comparing range to set limits

dino4u86

New Member
Joined
Nov 11, 2020
Messages
11
Office Version
  1. 2013
Platform
  1. Windows
Hi,

Im looking to create a VBA code that help me check my results for each region (Range A2:P9) against the limits of that region Range(G2:G9)

Results in Region 1 if greater than Limit of region 1 then highlight cell will color red. same goes for other regions

Request VBA code for the same.

Thanks
 

Attachments

  • ExcelVba1.PNG
    ExcelVba1.PNG
    18.2 KB · Views: 5

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Select B2:F9 & use this formula in conditional formatting.
Excel Formula:
=AND($B2<$G2,$B2<>"")
 
Upvote 0
That doesnt work as the entire row in the table gets selected and colored which is not what I want. I would like only the cell in every individual region to be colored that are breaking the limits and I need this in VBA please

attaching incorrect result
 

Attachments

  • ExcelVba2.PNG
    ExcelVba2.PNG
    31.1 KB · Views: 4
Upvote 0
OOps, you need to remove the $ sign from both B2 references, but leave it on the G2
 
Upvote 0
Solution
Thanks I managed to write the code:

'conditional formatting
ThisWorkbook.Sheets("XYZ").Activate
'Dim rng1 As Range
rng1 = Range(Range("F3"), Range("P3").End(xlDown).Offset(-2, 0)).Select
Range("rng1").FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=Abs(F3)>$P3"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent2
.TintAndShade = 0.599963377788629
End With
Selection.FormatConditions(1).StopIfTrue = False
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,178
Members
452,615
Latest member
bogeys2birdies

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