I am stuck and I don't know if there are any solutions to this as I have tried many and kept failing.
I am trying to add a conditional formatting so cells in column B turns yellow if it is equal or less than 19% of it's partner cell in column A. So in the example above, cell B1 should turn yellow since $19,000 is less than or equal to 19% of $100,000.
I need to add this conditional formatting through excel vba. I tried adding the vba code below but the conditional formatting formula for all of the cells in B1:B3 get's stuck with $A1*0.19
. I need B1 conditional formatting formula to be $A1*0.19
, then B2 conditional formatting formula would be $A2*0.19
so on and so fort. I have about 350 rows by the way not just 3. Even so, my vba code becomes $A521325*0.19
or something way off the real or actual.
With Sheet1.Range(Sheet1.Cells(1, 2), Sheet1.Cells(3, 2))
daformula = "=$A1*0.19"
.FormatConditions.Add Type:=xlCellValue, Operator:=xlLessEqual, Formula1:=daformula
.FormatConditions(.FormatConditions.Count).SetFirstPriority
.FormatConditions(1).Interior.PatternColorIndex = xlAutomatic
.FormatConditions(1).Interior.ThemeColor = xlThemeColorAccent2
.FormatConditions(1).Interior.TintAndShade = -0.249946592608417
.FormatConditions(1).StopIfTrue = False
End With
The idea is after running the macro which adds the conditional formatting to the sheet, when the user changes one of the cells in column B the color either disappear or reappear depending on the value the user changed the cell into (the conditional formatting must still work)