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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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,892
Messages
6,122,112
Members
449,066
Latest member
Andyg666

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