Hi,
Quote:
|
What I need is for the date 01/01/2010 to update to 01/02/2010 when the date has changed from January to February. If possible i would like it done in a macro that I already have attached to clear out old entries in the previous month.
|
To increase the month by one you can use a procedure such as this:
Code:
Sub foo()
Dim rngDates As Range
Dim strFormula As String
Set rngDates = Sheet1.Range("C2:C31")
strFormula = "=IF(ISNUMBER(" & rngDates.Address & "),DATE(YEAR(" & _
rngDates.Address & "),MONTH(" & rngDates.Address & ")+1,1),"""")"
rngDates = rngDates.Parent.Evaluate(strFormula)
End Sub
Just set rngDates to the range you need. It's up to you to choose the event that will trigger this code - clicking a button, opening the workbook, etc...
Quote:
|
I also have a question about Excel and recognising days of the week. How intelligent is Excel with regards to this. Is excel able to determine from the date of the month what day of the week it is and if so, could it then automatically update information in a cell (such as colouring a cell in if it was a saturday).
|
Yes, Excel has extensive worksheet functions for working with dates. There are also numerous functions in the VBA library.
In terms of worksheet functions, a formula such as this will visually tell you the day of the week:
=TEXT(A1,"ddd")
Where A1 holds a date.
Other functions that may be of interest are DAY() and WEEKDAY().
To highlight a cell you could use conditional formatting. The DAY() function returns 6 if it is a Saturday, so the conditional formatting formula in cell A1 would be something like this:
=DAY($A$1)=6
Hope that helps..