switch calendar control on/off

Biedubbeljoe

Active Member
Joined
Aug 16, 2004
Messages
308
Hello,

Can someone tell me how to switch the calendar control ON and OFF by a button on my worksheet?

The calendar control:

---------------------------------------------------------------------------
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not Application.Intersect(Range("G10:G400,H10:H400,I10:I400,J10:J400,K10:K400,L10:L400,M10:M400,N10:N400,O10:O400,P10:P400,Q10:Q400,R10:R400"), Target) Is Nothing Then
Calendar1.Left = Target.Left + Target.Width - Calendar1.Width
Calendar1.Top = Target.Top + Target.Height
Calendar1.Visible = True
Calendar1.GridFontColor = RGB(0, 0, 0)
Calendar1.BackColor = RGB(255, 255, 255)
Calendar1.DayFontColor = RGB(0, 0, 0)
Calendar1.TitleFontColor = RGB(0, 0, 0)
Calendar1.Value = Date
Else: Calendar1.Visible = False
End If

End Sub
-------------------------------------------------------------
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I made a checkbox and try to make the code working, but the private sub must be deleted, but I don't know how to make the code work. With the checkbox I can set the code ON or OFF by a button I made on my worksheet.
Can someone tell me how the code can work, if I erase the second private sub??

----------------------------------------------
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not Application.Intersect(Range("G10:G400,H10:H400,I10:I400,J10:J400,K10:K400,L10:L400,M10:M400,N10:N400,O10:O400,P10:P400,Q10:Q400,R10:R400"), Target) Is Nothing Then
Calendar1.Left = Target.Left + Target.Width - Calendar1.Width
Calendar1.Top = Target.Top + Target.Height
Calendar1.Visible = True
Calendar1.GridFontColor = RGB(0, 0, 0)
Calendar1.BackColor = RGB(255, 255, 255)
Calendar1.DayFontColor = RGB(0, 0, 0)
Calendar1.TitleFontColor = RGB(0, 0, 0)
Calendar1.Value = Date
Else: Calendar1.Visible = False
End If

End Sub

Else
' Turn OFF the code (do nothing)
If CheckBox1.Value = False Then
Exit Sub
End Sub
-----------------------------------
 
Upvote 0

Forum statistics

Threads
1,224,391
Messages
6,178,306
Members
452,839
Latest member
grdras

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top