Hi Again Darren,
Gary Keramidas has given you some code which I assume works and I extend my
thanks to him for his contribution.
However, I have modified it a bit to include your 548 days and used Case
because I think it is easier to understand and modify if you change your
mind. However, you need to realise with case that it processes only the first
true case. If there is more than one true then the extras are ignored. Of
course if none are true then Else runs.
The other thing is that you need to have the case statements in the correct
order if there is a priority. For example if you put the line 'Case Is < Date
+ 1 + 548' first then it would also run when the date is actually less than
today() because any date less than Date + 1 + 548 is true.
I have also put the code in to color the cell instead of the font. I find
that it is easier to find the cell and also yellow font is almost impossible
to read. If you want the font colored then simply remove the single quote
which makes it a comment and place it in front of the interior color lines of
code. There is a nice little table in help which you will find under 'color
index' if you want other colors.
Lastly, the first case is <= to include today(). If you do not want to
include today in the red then remove the = and it will then be included in
the yellow. Also the yellow does not include the last day in the second case;
only less than. Of course the +1+548 could be 549. I only put it that way
because that is how you described it.
Sub Color_Cells()
Dim ws As Worksheet
Dim cell As Range
For Each ws In ThisWorkbook.Worksheets
For Each cell In ws.UsedRange
If IsDate(cell) Then
Select Case cell
Case Is <= Date
'cell.Font.ColorIndex = 3 'Red
cell.Interior.ColorIndex = 3
Case Is < Date + 1 + 548
'cell.Font.ColorIndex = 6 'Yellow
cell.Interior.ColorIndex = 6
'Else is needed in case you correct a date
Case Else
'cell.Font.ColorIndex = 1 'Black
cell.Interior.ColorIndex = xlColorIndexNone
End Select
End If
Next cell
Next ws
End Sub
Regards,
OssieMac
"Darren_New2VBA" wrote:
> OssieMac...
>
> The dates are not always in the same cells (it varies and there can be
> up to 30 columns and 500 rows to check per sheet). The macro will also
> need to be applied to multiple worksheets. It may be easier said than
> done but basically i want the macro to search for a cell with a date in
> it, once located, check to see what formatting needs to be applied (eg:
> Change to Red, Green, Yellow, etc)...
>
> Im happy to run the macro manually for now, but eventually it will be
> something that i need to apply monthly (but for now, manual is fine)...
>
> As for the dates (31 Jan 2009 or 03 Feb 2009) it needs to be based on
> Days not months/years (1.5 years equalling 548 days)...basically i need
> a warning to appear (color coding) if the certification im looking at
> has past an 18month (548 day) period...
>
> Im utilising MS Excel 2003
>
> I dont have a specific deadline for this, i just need to analyse the
> data for trends at this stage then apply it to some monthly reports...
>
> Cheers...Darren
>
> *** Sent via Developersdex http://www.developersdex.com ***
>