Set cell background based on date.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I saw a post similar to this earlier this week. I However i was unbale to get
it to work. My question is: I am working a caladar for work. I want a certian
set of cells to be highlighted, color is unimportant, based on todays date.
So if I open the workbook today, Oct. 28th will be highlighted. Tomorrow Oct
29th will be highlighted.

Thanks for your help,
Steve
 
sorry for the multiple postings. The first time i submitted it, i got an
error message.

Steve
 
Steve,

This will get you started. Drop this into the worksheet's module.

Option Explicit

Private Sub Worksheet_Activate()
Dim rngCell As Range

For Each rngCell In Me.Range(Me.Cells(1, 1),
Me.Cells.SpecialCells(xlCellTypeLastCell))
If rngCell.Value = Date Then
rngCell.Interior.Color = RGB(0, 0, 225)
ElseIf rngCell.Value = Date + 1 Then
rngCell.Interior.Color = RGB(255, 255, 0)
ElseIf IsDate(rngCell.Value) Then
rngCell.Interior.ColorIndex = xlColorIndexNone
End If
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top