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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,358
Office Version
  1. 365
Platform
  1. Windows
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,191,718
Messages
5,988,267
Members
440,146
Latest member
rgomes8

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
Top