Hi all, hoping someone can help me with this problem please.
I'll start by saying that I am not familiar with VBA and have mostly cobbled this code together by reading various posts on this forum so apologies if the code is total rubbish!
I have added a Date Picker Control to my sheet and want it to appear next to the selected cell but only in columns 1, 4 and 6
I have managed to get it to do this but there are some side effects....!
After I have selected a cell for the first time subsequent selections cause the date picker to appear next to the new selected cell but only as a drawing object. The active picker remains next to the original cell that was selected. i.e. I now have 2 pickers displayed but only the original actually does anything.
This original stays in the same place no matter which subsequent cell I select.
Both copies do disappear if I select a cell that isn't in columns 1, 4 or 6 or if I scroll the mouse wheel but not if I use the arrow keys to select new cells or click to select a new cell.
Hopefully that makes some sense, code pasted below if anyone can help clean it up and get it working that would be great. I have named the Calendar Control Calendar1 in the properties screen but all other values have been left at default. I am using Excel 2010 on a 32 bit OS if that makes any difference.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Calendar1.Visible Then Calendar1.Visible = False
Select Case Target.Column
Case 1, 4, 6
If Target.Count > 1 Then Exit Sub
Calendar1.Left = Target.Left + Target.Width
Calendar1.Top = Target.Top + Target.Height
Calendar1.Visible = True
Calendar1.Value = Date
Case Else: Exit Sub
End Select
End Sub
Private Sub Calendar1_Click()
ActiveCell = Calendar1.Value
Calendar1.Visible = False
ActiveCell.Select
End Sub
Thanks in advance, Ian
I'll start by saying that I am not familiar with VBA and have mostly cobbled this code together by reading various posts on this forum so apologies if the code is total rubbish!
I have added a Date Picker Control to my sheet and want it to appear next to the selected cell but only in columns 1, 4 and 6
I have managed to get it to do this but there are some side effects....!
After I have selected a cell for the first time subsequent selections cause the date picker to appear next to the new selected cell but only as a drawing object. The active picker remains next to the original cell that was selected. i.e. I now have 2 pickers displayed but only the original actually does anything.
This original stays in the same place no matter which subsequent cell I select.
Both copies do disappear if I select a cell that isn't in columns 1, 4 or 6 or if I scroll the mouse wheel but not if I use the arrow keys to select new cells or click to select a new cell.
Hopefully that makes some sense, code pasted below if anyone can help clean it up and get it working that would be great. I have named the Calendar Control Calendar1 in the properties screen but all other values have been left at default. I am using Excel 2010 on a 32 bit OS if that makes any difference.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Calendar1.Visible Then Calendar1.Visible = False
Select Case Target.Column
Case 1, 4, 6
If Target.Count > 1 Then Exit Sub
Calendar1.Left = Target.Left + Target.Width
Calendar1.Top = Target.Top + Target.Height
Calendar1.Visible = True
Calendar1.Value = Date
Case Else: Exit Sub
End Select
End Sub
Private Sub Calendar1_Click()
ActiveCell = Calendar1.Value
Calendar1.Visible = False
ActiveCell.Select
End Sub
Thanks in advance, Ian