Multiple Conditional Formatting Rules in VBA

NEW_2VBA

Board Regular
Joined
Dec 15, 2015
Messages
106
[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]D
[/TD]
[TD]E
[/TD]
[TD]F
[/TD]
[TD]G
[/TD]
[TD]H
[/TD]
[TD]I
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]Invoice Date
[/TD]
[TD]Amount
[/TD]
[TD]Check Date
[/TD]
[TD]Check #
[/TD]
[TD]$ Inv Paid
[/TD]
[TD]Check $
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]6/1/2002
[/TD]
[TD]$5000
[/TD]
[TD]6/23/2002
[/TD]
[TD]1234
[/TD]
[TD]$0.00
[/TD]
[TD]$0.00
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]5/1/2003
[/TD]
[TD]$4400
[/TD]
[TD]5/15/2003
[/TD]
[TD]4576
[/TD]
[TD]$4400
[/TD]
[TD]$8000
[/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD]7/5/2004
[/TD]
[TD]$100
[/TD]
[TD]7/28/2004
[/TD]
[TD]9886
[/TD]
[TD]$500
[/TD]
[TD]$6000
[/TD]
[/TR]
</tbody>[/TABLE]

Happy New Year! I need some guidance for creating vba code to run multiple conditional formatting rules.

  1. On Column F = D2+20>F2 Check date must be 20 days after invoice date, if not = condl highlight
  2. On Column H = H2<>E2 Amount should = $ Inv Paid, if not = condl highlight
  3. On Column I = I2<H2 Check $ must be greater than $ Inv Paid, if not = condl
For all rules I'd just like to highlight the cell if the value is true Interior.Color=RGB(248,203,173)




Here's what I have so far..

With Range("F2").FormatConditions.Add(Type:=xlExpression, Formula1:="=D2+20>F2")
.Interior.Color = RGB(248, 203, 173)
End With
Range("F2").NumberFormat = "m/d/yyyy"

With Range("H2").FormatConditions.Add(Type:=xlCellValue, Operator:=xlNotEqual, Formula1:="=E2")
.Interior.Color = RGB(248, 203, 173)
End With
With Range("I2").FormatConditions.Add(Type:=xlCellValue, Operator:=xlLess, Formula1:="=H2")
.Interior.Color = RGB(248, 203, 173)
End With



 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
How about
Code:
Dim Lr As Long
Lr = Range("D" & Rows.Count).End(xlUp).Row
With Range("F2:F" & Lr).FormatConditions.Add(Type:=xlExpression, Formula1:="=D2+20>F2")
   .Interior.Color = RGB(248, 203, 173)
End With
Range("F2:F" & Lr).NumberFormat = "m/d/yyyy"

With Range("H2:H" & Lr).FormatConditions.Add(Type:=xlCellValue, Operator:=xlNotEqual, Formula1:="=E2")
   .Interior.Color = RGB(248, 203, 173)
End With
With Range("I2:I" & Lr).FormatConditions.Add(Type:=xlCellValue, Operator:=xlLess, Formula1:="=H2")
   .Interior.Color = RGB(248, 203, 173)
End With
 
Upvote 0
Thanks for the feedback. I used the code above & checked "Manage Rules" and noticed all three conditional formatting rules were listed however only the first one was applied.
I read something about specifying "StopifTrue=False" or possibly setting priority but not too familiar with adding those instructions into code.
 
Upvote 0
This is what I get with that code
+Fluff 1.xlsm
DEFGHI
1Invoice DateAmountCheck DateCheck #$ Inv PaidCheck $
201/06/2002500023/06/2002123400
301/05/2003440015/05/2003457644004000
405/07/200410028/07/200498865006000
Main
Cells with Conditional Formatting
CellConditionCell FormatStop If True
F2:F4Expression=D2+20>F2textYES
H2:H4Cell Value<>E2textYES
I2:I4Cell Value<H2textYES
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
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