Color not set when Conditional Formatting applied using VBA

forgetso

Board Regular
Joined
Sep 18, 2007
Messages
198
Hi,

I have a macro that sets some conditional formatting for two columns as follows:

Code:
Option Explicit
Sub ApplyFormatting()
Dim i As Integer
Dim letter As String

For i = 16 To 17
    letter = ColumnLetter(i)
    Columns(i).Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=IF(WEEKDAY(NOW(),16)=WEEKDAY(" + letter + "$2,16),1,0)"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetLastPriority
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent5
        .TintAndShade = 0.799981688894314
    End With
    Selection.FormatConditions(1).StopIfTrue = False
Next
End Sub

However, the .TintAndShade is never set correctly. The rule is created but under color it simply says "No Format Set".

Anyone know why this is happening?

Cheers
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Are you sure that the condition you are adding is the first one - FormatConditions(1)? Maybe you need to delete the existing conditions first.

By the way you should use & rather than + for concatenation.
 
Upvote 0
ah ha! It is definitely not the first condition. There are about 10-20 other conditions in front of it. Thank you!

I'll remember about the "&" as well. I'm used to .'s in php and +'s in js.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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