Good Afternoon,
I have a worksheet that is conditionally formatted to use 6 formulas. Every time a user pastes in the worksheet, they are messing up the formatting. I understand I can create a VBA to delete and reapply formatting.
I found some formatting that rlv01 (Thank you!) had posted on a similar question. I adjusted the code to fit with what I needed and so far it has worked great. My only issue is that I can only get it to one condition. I had tried changing it to 2 conditions but the last condition would overwrite the first. I need a way to combine both of these VBA's.
Thank you!
I have a worksheet that is conditionally formatted to use 6 formulas. Every time a user pastes in the worksheet, they are messing up the formatting. I understand I can create a VBA to delete and reapply formatting.
I found some formatting that rlv01 (Thank you!) had posted on a similar question. I adjusted the code to fit with what I needed and so far it has worked great. My only issue is that I can only get it to one condition. I had tried changing it to 2 conditions but the last condition would overwrite the first. I need a way to combine both of these VBA's.
VBA Code:
Sub Green()
Dim FCRange As Range
Dim FormulaStr As String, DQ As String
Dim WS As Worksheet
Set WS = ActiveSheet 'define worksheet containing format conditions.
Set FCRange = WS.Range("A14:Q200") 'define the range of cells you want to 'refresh'
With FCRange.FormatConditions
.Delete 'It is important to clear existing format conditions each time the macro is run
DQ = """" 'double quote
FormulaStr = "=AND(NOT(ISBLANK($B14)),AND($B14*$E$8=$O14,$P14=0))" & DQ 'Any formula that resolves to True or False
'Set format condition
With .Add(Type:=xlExpression, Formula1:=FormulaStr)
.StopIfTrue = True
.Interior.Color = RGB(198, 239, 206)
.Font.Color = RGB(0, 0, 0)
End With
End With
End Sub
VBA Code:
Sub Red()
Dim FCRange As Range
Dim FormulaStr As String, DQ As String
Dim WS As Worksheet
Set WS = ActiveSheet 'define worksheet containing format conditions.
Set FCRange = WS.Range("A14:Q200") 'define the range of cells you want to 'refresh'
With FCRange.FormatConditions
.Delete 'It is important to clear existing format conditions each time the macro is run
DQ = """" 'double quote
FormulaStr = "=AND($M14<TODAY(),NOT($B14<=0))" & DQ 'Any formula that resolves to True or False
'Set format condition
With .Add(Type:=xlExpression, Formula1:=FormulaStr)
.StopIfTrue = True
.Interior.Color = RGB(255, 199, 206)
.Font.Color = RGB(0, 0, 0)
End With
End With
End Sub
Thank you!