Option Buttons

Joined
Jul 25, 2007
Messages
26
Reaction score
0
To All,
I have a userform which has a calendar on it. when a date is selected the active cell is filled with the date. What I am trying to do is format the active cell by the choosing of an option button. I am able to have the cell formatted to what I want the first time a date is picked. but the second time the format reverts back to the origional formating. If I select another option button the new fornmatting works but not twice in a row.
Thanks if some one can help me.

Private Sub UserForm_Initialize()
Const PROC_NAME As String = "UserForm_Initialize"
On Error Resume Next
Dim i As Long, FirstOfMonth As Long, LastOfMonth As Long
FirstOfMonth = DateSerial(myCalYear, myCalMonth, 1)
LastOfMonth = DateSerial(myCalYear, myCalMonth + 1, 0)
SpinButtonYear.Value = myCalYear
SpinButtonMonth.Value = myCalMonth
For i = 1 To 42
With Me.Controls("Label" & i)
If Application.Weekday(FirstOfMonth, srtDay) - i >= 1 Or Day(LastOfMonth) < _
Application.Sum(i - Application.Weekday(FirstOfMonth, srtDay)) + 1 Then
.Visible = False
Else
.Visible = True
.Caption = Application.Sum(i - Application.Weekday(FirstOfMonth, srtDay)) + 1
.ControlTipText = "Push to enter date"

Selection.NumberFormat = "[$-C09]dddd, d mmmm yyyy;@"

If i = Day(Now) + Application.Weekday(FirstOfMonth, srtDay) - 1 _
And myCalYear = Year(Date) And myCalMonth = Month(Date) Then
.BackColor = RGB(204, 255, 255)
Else
.BackColor = RGB(255, 255, 255)
End If
End If
End With
Next
LabelYear.Caption = Format(DateSerial(1, myCalMonth, 1), "mmmm") & ", " & myCalYear
If srtDay = 2 Then
LabelWeekdays.Caption = " Mo Tu We Th Fr Sa Su"
Label1.ForeColor = RGB(0, 0, 0)
Label8.ForeColor = RGB(0, 0, 0)
Label15.ForeColor = RGB(0, 0, 0)
Label22.ForeColor = RGB(0, 0, 0)
Label29.ForeColor = RGB(0, 0, 0)
Label36.ForeColor = RGB(0, 0, 0)
Label7.ForeColor = RGB(255, 0, 0)
Label14.ForeColor = RGB(255, 0, 0)
Label21.ForeColor = RGB(255, 0, 0)
Label28.ForeColor = RGB(255, 0, 0)
Label35.ForeColor = RGB(255, 0, 0)
Me.CommandButtonWeekStart.Caption = _
"Start from" & Chr(10) & "Sundays?"
Else
LabelWeekdays.Caption = " Su Mo Tu We Th Fr Sa"
Label1.ForeColor = RGB(255, 0, 0)
Label8.ForeColor = RGB(255, 0, 0)
Label15.ForeColor = RGB(255, 0, 0)
Label22.ForeColor = RGB(255, 0, 0)
Label29.ForeColor = RGB(255, 0, 0)
Label36.ForeColor = RGB(255, 0, 0)
Label7.ForeColor = RGB(0, 0, 0)
Label14.ForeColor = RGB(0, 0, 0)
Label21.ForeColor = RGB(0, 0, 0)
Label28.ForeColor = RGB(0, 0, 0)
Label35.ForeColor = RGB(0, 0, 0)
Me.CommandButtonWeekStart.Caption = _
"Start from" & Chr(10) & "Mondays?"
End If
iChangeSettings = iChangeSettings + 1
If GetSetting(UtilsName, Me.Name, "Left") = "" _
And GetSetting(UtilsName, Me.Name, "Top") = "" Then
Me.StartUpPosition = 1 ' CenterOwner
Else
Me.Left = GetSetting(UtilsName, Me.Name, "Left")
Me.Top = GetSetting(UtilsName, Me.Name, "Top")
End If
AddIconToUserForms Me

On Error GoTo 0
End Sub

Geoffrey Barnard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top