Conditional Formatting using VBA

eoinymc

Board Regular
Joined
Jan 29, 2009
Messages
203
Hi,

I am trying to do conditional formatting within a macro because the range changes each month when I run it...

However, it is throwing up a confusing issue...Here is the code

Code:
[/COLOR]Dim T1 As Worksheet, _        Upd As Worksheet
    Set T1 = Sheets("Table 1")
    Set Upd = Sheets("Update")
    
FRT1S = T1.Cells(Rows.Count, 2).End(xlUp).Row


Dim rng1 As Range
    Set rng1 = T1.Range(Cells(8, 2), Cells(FRT1S, 18))
    
    With rng1.FormatConditions
        .Delete
        .Add Type:=xlExpression, Formula1:="=$S8=$Z$6"
    End With
    
    With rng1.FormatConditions(1)
        With .Font
            .Bold = True
            .ColorIndex = 2
        End With
        With .Interior
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorAccent1
            .TintAndShade = 0.399945066682943
        End With
        With .Borders
            .ThemeColor = 5
            .TintAndShade = 0
            .Weight = xlThin
        End With 

    End With[COLOR=#333333]

So, when I run the code and look at the conditional formatting on the sheet, instead of seeing =$S8=$Z$6, I see =$S9=$Z$6 and it highlights the row above the row I'm looking for?!

Any idea why this is?

I'm using Excel 2007. I got a colleague to run it and he is using Excel 2010 and it seems to work fine for him...it's quite annoying and has been perplexing me for a number of hours now!!!!

Any help will be greatly appreciated.

Cheers,

E
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Have you tried putting the conditional format in a loop to apply the formatting to each row individually?

You should have to do this but it might solve the problem until someone can think of a better solution.
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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