Thread: Calendar mod
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ken McLennan[_3_] Ken McLennan[_3_] is offline
external usenet poster
 
Posts: 90
Default Calendar mod

G'day there again,

Leaving aside the simultaneous updating mentioned in a previous
thread, I've found that the worksheet calendar from John Walkenbach's
book is causing me problems. I've modified it, as per John's suggestion,
to show dates for the entire work area. That is, I've removed the If
function from the array formula and so have 42 dates shown. All else is
the same as the original.

What I've also done is to place code in the Worksheet_Calculate()
event to check the month of the date shown. If the date is in the
current month, then the forecolor is blue & bold. If it's in the
previous or next month, it's not bold and coloured black. Now here's the
puzzling bit:

If I change the date using the scroll bars on top of the calendar,
the cells are updated with the required formatting. Hence the
Worksheet_Calculate() event code is working. However, if I press the
"Current Month" button, the code hangs with a "Runtime error 1004...
Unable to set the Color property of the Font class" message. Likewise,
the same error is generated from trying to "get" the color property in
the immediate window.

Why is that? the code is the same, the only difference that I can
see is that the setting of month & year are done programatically by
calling a general module to change the scrollbars instead of clicking on
them. The Worksheet_Calculate() code is still called, except that now it
can't do anything with the .font properties.

Here is the Worksheet_Calculate() code:

Note that one uses [calarray], the other uses Me.Range...
just to demonstrate that I've used both types of reference. Same problem
with both methods. ( 'calarray' is the range of the 42 "date" cells in
the calendar)

Private Sub Worksheet_Calculate()
Dim X As Integer
Dim Y As Integer
For Y = 1 To 6
For X = 1 To 7
If Month([calarray].Cells(Y, X).Value) < Me.Range
("m").Value Then
With [calarray].Cells(Y, X).Font
.Color = vbBlack
.Bold = False
End With
Else
With Me.Range("calarray").Cells(Y, X).Font
.Color = vbBlue
.Bold = True
End With
End If
Next X
Next Y

End Sub

Hoping for a suggestion,
Ken McLennan
Qld, Australia