Excel Conditional Formatting "moves" with selection, when set from VBScript
Nicolas Galler | September 15, 2007This is an odd one… If you set a conditional formatting on an entire column (or a range) in Excel, and you use a relative reference (one that is not anchored with a dollar sign), and the currently selected cell is not the first one in the range… all the references will be shifted.
For example:
xlsWsh.Range("H1:H20").FormatConditions.Add xlExpression, , "=$B1=0"
Note I anchored the column, but not the row.
If prior to running this code the cell H8 was selected, then H8 will have as formula in the format condition, “=$B1=0″, instead of the expected “=$B8=0″.
The solution I used for now is to do
xlsWsh.Range("H1").Select
prior to running the rest.
Oh and strangely enough it seemed to run without problem from the VBA within Excel.





