ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   CF (If Formula Is ) placed into macro (https://www.excelbanter.com/excel-programming/422341-cf-if-formula-placed-into-macro.html)

Driftwood

CF (If Formula Is ) placed into macro
 
In row 5 (C5 - AF5) are dates from 1 - 31
Then from C8 - AG25 I will need the cells under the column
for the weekends to be gray by macro.
I have always used conditional formatting for this, but now
I will have to use my three CF's for something other than specifying the
weekends
How do I put these CF's into a macro to format
the cells light gray from C8 - AG25 ?
If Formula is =WEEKDAY(E$5,2)=6
If Formula is =WEEKDAY(F$5,2)=7
etc

Bernard Liengme

CF (If Formula Is ) placed into macro
 
I recorded a macro to make the active cell grey if E5 was a weekend. Here is
the result

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 12/01/2009 by Bernard V Liengme
'

'
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=WEEKDAY(E$5,2)=6"
Selection.FormatConditions(1).Interior.ColorIndex = 15
End Sub

Using that as a guid I coded this
Sub Macro2()
With Range("G10")
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=WEEKDAY(E$5,2)=6"
.FormatConditions(1).Interior.ColorIndex = 15
End With
End Sub

best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"Driftwood" wrote in message
...
In row 5 (C5 - AF5) are dates from 1 - 31
Then from C8 - AG25 I will need the cells under the column
for the weekends to be gray by macro.
I have always used conditional formatting for this, but now
I will have to use my three CF's for something other than specifying the
weekends
How do I put these CF's into a macro to format
the cells light gray from C8 - AG25 ?
If Formula is =WEEKDAY(E$5,2)=6
If Formula is =WEEKDAY(F$5,2)=7
etc





All times are GMT +1. The time now is 10:32 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com