Conditioal Format in VBA Formula is changed from entered

srcera

Board Regular
Joined
May 22, 2006
Messages
95
I have the following code which sets a conditional format. However, when I look at the conditional format of any cell in the range C2:K200, the formula is different. It references the wrong cell. For example, after running the code, the formula for cell C2 is now

=IF(ISNUMBER(B2),IF(B2<0.298,TRUE,FALSE),FALSE)

B2 should be C2.
ThisWorkbook.Sheets("Inspection").Range("$C$2:$K$200").FormatConditions.Delete
'Highlight Thin Spots
ThisWorkbook.Sheets("Inspection").Range("$C$2:$K$200").FormatConditions.Add Type:=xlExpression, _
Formula1:="=IF(ISNUMBER(C2),IF(C2<" & dMinPlateThickness & ",TRUE,FALSE),FALSE)"
ThisWorkbook.Sheets("Inspection").Range("$C$2:$K$200").FormatConditions(1).Interior.ColorIndex = 46


Any help would be appreciated.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try changing the formula to R1C1 notation.
Code:
ThisWorkbook.Sheets("Inspection").Range("$C$2:$K$200").FormatConditions.Add Type:=xlExpression, _
Formula1:="=IF(ISNUMBER(RC),IF(RC<" & dMinPlateThickness & ",TRUE,FALSE),FALSE)"
 
Upvote 0

Forum statistics

Threads
1,214,400
Messages
6,119,284
Members
448,885
Latest member
LokiSonic

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