Multiple Conditional Formatting Rules in VBA

NEW_2VBA

Board Regular
Joined
Dec 15, 2015
Messages
106
D
E
F
G
H
I
1
Invoice Date
Amount
Check Date
Check #
$ Inv Paid
Check $
2
6/1/2002
$5000
6/23/2002
1234
$0.00
$0.00
3
5/1/2003
$4400
5/15/2003
4576
$4400
$8000
4
7/5/2004
$100
7/28/2004
9886
$500
$6000

<tbody>
</tbody>

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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
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,216,747
Messages
6,132,482
Members
449,729
Latest member
davelevnt

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