View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default first Tuesday in the month

On Sat, 29 Nov 2003 23:26:26 +1100, "DL" wrote:

I want to use a vba procedure to examine the dates in a calendar and
highlight all those that are the first Tuesday in the month.

Can this be done?



Well, a formula which will compute the first Tuesday in any given month is:


=DATE(YEAR(A1),MONTH(A1),1)+CHOOSE(WEEKDAY(DATE(YE AR(A1),MONTH(A1),1)),2,1,0,6,5,4,3)

So you could use Conditional Formatting. You could certainly use VBA to apply
conditional formatting to the range in which your calendar exists.

In VBA code it might be something like:


calendar.FormatConditions.Delete
calendar.FormatConditions.Add Type:=xlExpression, Formula1:= _

"=A1=DATE(YEAR(A1),MONTH(A1),1)+CHOOSE(WEEKDAY(DAT E(YEAR(A1),MONTH(A1),1)),2,1,0,6,5,4,3)"
calendar.FormatConditions(1).Interior.ColorIndex = 15

where 'calendar' represents the range where the calendar is stored.






--ron