Highlight current date cell

bob85

New Member
Joined
Jan 13, 2009
Messages
3
Hello, <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
I am working on a calendar where I need the current day to be highlighted. I know how to do it with conditional formatting but I would like to use VB for it. I have come up with the following code but it does not work. Any help would be appreciated.<o:p></o:p>
<o:p></o:p>
Private Sub Workbook_Open() <o:p></o:p>
Dim cCurrDate As String
cCurrDate = Format(Date, "mm/dd/yyyy")
If Range("C5:AG31").Value = cCurrDate Then
Font.ColorIndex = 3
Else
Font.ColorIndex = 0
End If<o:p></o:p>
End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
You need to loop through each cell in the range

Private Sub Workbook_Open()
Dim cCurrDate As String
Dim cell As Range
cCurrDate = Format(Date, "mm/dd/yyyy")

For each cell in Range("C5:AG31")
If cell.Value = cCurrDate Then
cell.Font.ColorIndex = 3
Else
cell.Font.ColorIndex = 0
End If
Next cell
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,251
Members
448,556
Latest member
peterhess2002

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