ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Calendar control (https://www.excelbanter.com/excel-discussion-misc-queries/68174-calendar-control.html)

Shane

Calendar control
 
I have this code in an excel sheet, it brings up a calendar when I click a
cell in the range A1:A20, I can then click on a date and it populates the
cell selected with that date.



Problem is, I need this to apply to range C1:C20 and G1:G20, got any idea
how I can add the extra ranges in?



Thanks



Shane



Private Sub Calendar1_Click()

ActiveCell.Value = CDbl(Calendar1.Value)

ActiveCell.NumberFormat = "dd/mm/yyyy"

ActiveCell.Select

End Sub



Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Cells.Count 1 Then Exit Sub

If Not Application.Intersect(Range("A1:A50"), Target) Is Nothing Then

Calendar1.Left = Target.Left + Target.Width + Calendar1.Width

Calendar1.Top = Target.Top + Target.Height

Calendar1.Visible = True

' select Today's date in the Calendar

Calendar1.Value = Date

ElseIf Calendar1.Visible Then Calendar1.Visible = False

End If

End Sub





Ian

Calendar control
 
Your code selcts on A1 to A50, not A20 as you specified in the query.
This should select on A1:A20, C1:C20 and G1:G20
If Not Application.Intersect(Range("A1:A20,C1:C20,G1:G20" ), Target) Is
Nothing Then


--
Ian
--
"Shane" wrote in message
...
I have this code in an excel sheet, it brings up a calendar when I click a
cell in the range A1:A20, I can then click on a date and it populates the
cell selected with that date.



Problem is, I need this to apply to range C1:C20 and G1:G20, got any idea
how I can add the extra ranges in?



Thanks



Shane



Private Sub Calendar1_Click()

ActiveCell.Value = CDbl(Calendar1.Value)

ActiveCell.NumberFormat = "dd/mm/yyyy"

ActiveCell.Select

End Sub



Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Cells.Count 1 Then Exit Sub

If Not Application.Intersect(Range("A1:A50"), Target) Is Nothing Then

Calendar1.Left = Target.Left + Target.Width + Calendar1.Width

Calendar1.Top = Target.Top + Target.Height

Calendar1.Visible = True

' select Today's date in the Calendar

Calendar1.Value = Date

ElseIf Calendar1.Visible Then Calendar1.Visible = False

End If

End Sub







Shane

Calendar control
 
Thank you very much

Shane

"Ian" wrote:

Your code selcts on A1 to A50, not A20 as you specified in the query.
This should select on A1:A20, C1:C20 and G1:G20
If Not Application.Intersect(Range("A1:A20,C1:C20,G1:G20" ), Target) Is
Nothing Then


--
Ian
--
"Shane" wrote in message
...
I have this code in an excel sheet, it brings up a calendar when I click a
cell in the range A1:A20, I can then click on a date and it populates the
cell selected with that date.



Problem is, I need this to apply to range C1:C20 and G1:G20, got any idea
how I can add the extra ranges in?



Thanks



Shane



Private Sub Calendar1_Click()

ActiveCell.Value = CDbl(Calendar1.Value)

ActiveCell.NumberFormat = "dd/mm/yyyy"

ActiveCell.Select

End Sub



Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Cells.Count 1 Then Exit Sub

If Not Application.Intersect(Range("A1:A50"), Target) Is Nothing Then

Calendar1.Left = Target.Left + Target.Width + Calendar1.Width

Calendar1.Top = Target.Top + Target.Height

Calendar1.Visible = True

' select Today's date in the Calendar

Calendar1.Value = Date

ElseIf Calendar1.Visible Then Calendar1.Visible = False

End If

End Sub









All times are GMT +1. The time now is 11:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com