Thread: Code assistance
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Joe[_46_] Joe[_46_] is offline
external usenet poster
 
Posts: 48
Default Code assistance

Hi SF,

Try this ....
The code is given below...



Private Sub CommandButton1_Click()
' Will add a sheet and put all the dates of a month in 2nd column
' with weekends in Grey Color

Dim Y, M, D As Variant
Const CGrey As Integer = 15 ' or Assign the color code of ur choice
Dim i As Integer


M = Month(Now()) ' or Assign the number of the month (1, 2, ....,
12)
Y = Year(Now()) ' or Assign ur choice. (2007, 2008, ...)
i = 1

Sheets.Add
ActiveSheet.Name = "DD" 'Assign Ur text here

Do While Month(DateSerial(Y, M, i)) = M
With ActiveSheet
.Cells(i, 2) = DateSerial(Y, M, i)
D = Weekday(.Cells(i, 2), vbMonday)
If D = 6 Or D = 7 Then .Cells(i, 2).Interior.ColorIndex =
CGrey
End With
i = i + 1
Loop

End Sub




Check and let me know....

HTH,
Joe