Date picker calendars & combo box code questions.

dhm

New Member
Joined
Nov 18, 2009
Messages
4
Hi all,</SPAN>

I’ll try and keep it succinct & thanks in advance to any responses.</SPAN></SPAN>

The following code I have cobbled together (and indeed it truly looks like it!) from various sources and by sheer luck more than judgement it works</SPAN>, however it is not without some niggles.</SPAN></SPAN>

Currently there are five items that are using the code</SPAN></SPAN>


  • 3 date picker calendars</SPAN></SPAN>
  • 2 combo boxes using validation lists</SPAN></SPAN>

Issues that I would be most grateful for help on are:</SPAN></SPAN>

When I reopen the file and select any of the three cells that have the calendar/dates option the drop down box fills the entire screen instead of showing just the date and the drop down arrow to select a date from the calendar. If I go into the developer tab and perhaps select design mode or go into the visual basic screen and randomly move around the screen, upon return to the spread sheet the calendar cells revert back to behaving as I’d expect!? The sizes in the properties do not change and the file is enabled for macros. A way to create consistency when the file is opened so that selecting the calendar cell does not cause general user panic would be great.</SPAN></SPAN>

There are two combo boxes currently, however this could increase to double figures (form for users to fill in and this is hopefully making it easier for them and more accurate info upon return using the validation lists etc), the first one worked OK however when typing in the combo box it shrank to show only the letters being typed (a feature now lost since the addition of the second combo box, as is the larger font size that had been applied in the properties). When the data is selected in the list it also requires a double click to ‘exit’ the combo box which is not particularly user friendly and may cause non-technical users concern. </SPAN></SPAN>

If an example can be posted of how the calendars & two combo boxes should look in terms of code to alleviate the above issues I’m sure I could add in others successfully and that would be a massive help.</SPAN></SPAN>

Thanks again and I look forward to seeing how this works out</SPAN></SPAN>

Regards</SPAN></SPAN>

DHM </SPAN></SPAN>

CODE…..</SPAN></SPAN>

Private Sub Workbook_Open()</SPAN></SPAN>
Application.ScreenUpdating = False</SPAN></SPAN>
Workbooks.Add</SPAN></SPAN>
ActiveWindow.Close</SPAN></SPAN>
Application.ScreenUpdating = True</SPAN></SPAN>
End Sub</SPAN></SPAN>



Private Sub ROOMCOMBO_Change()</SPAN></SPAN>

End Sub</SPAN></SPAN>

'==========================</SPAN></SPAN>
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _</SPAN></SPAN>
Cancel As Boolean)</SPAN></SPAN>
Dim str As String</SPAN></SPAN>
Dim cboTemp As OLEObject</SPAN></SPAN>
Dim ws As Worksheet</SPAN></SPAN>
Dim wsList As Worksheet</SPAN></SPAN>
Set ws = ActiveSheet</SPAN></SPAN>
Set wsList = Sheets("ValidationLists")</SPAN></SPAN>

Cancel = True</SPAN></SPAN>
Set cboTemp = ws.OLEObjects("roomcombo")</SPAN></SPAN>
On Error Resume Next</SPAN></SPAN>
With cboTemp</SPAN></SPAN>
'clear and hide the combo box</SPAN></SPAN>
.ListFillRange = ""</SPAN></SPAN>
.LinkedCell = ""</SPAN></SPAN>
.Visible = False</SPAN></SPAN>
End With</SPAN></SPAN>
On Error GoTo errHandler</SPAN></SPAN>
If Target.Validation.Type = 3 Then</SPAN></SPAN>
'if the cell contains a data validation list</SPAN></SPAN>
Application.EnableEvents = False</SPAN></SPAN>
'get the data validation formula</SPAN></SPAN>
str = Target.Validation.Formula1</SPAN></SPAN>
str = Right(str, Len(str) - 1)</SPAN></SPAN>
With cboTemp</SPAN></SPAN>
'show the combobox with the list</SPAN></SPAN>
.Visible = True</SPAN></SPAN>
.Left = Target.Left</SPAN></SPAN>
.Top = Target.Top</SPAN></SPAN>
.Width = Target.Width + 55</SPAN></SPAN>
.Height = Target.Height + 5</SPAN></SPAN>
.ListFillRange = str</SPAN></SPAN>
.LinkedCell = Target.Address</SPAN></SPAN>
End With</SPAN></SPAN>
cboTemp.Activate</SPAN></SPAN>
'open the drop down list automatically</SPAN></SPAN>
Me.ROOMCOMBO.DropDown</SPAN></SPAN>

End If</SPAN></SPAN>

errHandler:</SPAN></SPAN>
Application.EnableEvents = True</SPAN></SPAN>
Exit Sub</SPAN></SPAN>


Cancel = True</SPAN></SPAN>
Set cboTemp = ws.OLEObjects("areacombo")</SPAN></SPAN>
On Error Resume Next</SPAN></SPAN>
With cboTemp</SPAN></SPAN>
'clear and hide the combo box</SPAN></SPAN>
.ListFillRange = ""</SPAN></SPAN>
.LinkedCell = ""</SPAN></SPAN>
.Visible = False</SPAN></SPAN>
End With</SPAN></SPAN>
On Error GoTo errHandler</SPAN></SPAN>
If Target.Validation.Type = 3 Then</SPAN></SPAN>
'if the cell contains a data validation list</SPAN></SPAN>
Application.EnableEvents = False</SPAN></SPAN>
'get the data validation formula</SPAN></SPAN>
str = Target.Validation.Formula1</SPAN></SPAN>
str = Right(str, Len(str) - 1)</SPAN></SPAN>
With cboTemp</SPAN></SPAN>
'show the combobox with the list</SPAN></SPAN>
.Visible = True</SPAN></SPAN>
.Left = Target.Left</SPAN></SPAN>
.Top = Target.Top</SPAN></SPAN>
.Width = Target.Width + 55</SPAN></SPAN>
.Height = Target.Height + 5</SPAN></SPAN>
.ListFillRange = str</SPAN></SPAN>
.LinkedCell = Target.Address</SPAN></SPAN>
End With</SPAN></SPAN>
cboTemp.Activate</SPAN></SPAN>
'open the drop down list automatically</SPAN></SPAN>
Me.areacombo.DropDown</SPAN></SPAN>

End If</SPAN></SPAN>


End Sub</SPAN></SPAN>

Private Sub Calendar1_Click()</SPAN></SPAN>
ActiveCell.Value = CDbl(Calendar1.Value)</SPAN></SPAN>
ActiveCell.NumberFormat = "mm/dd/yyyy"</SPAN></SPAN>
ActiveCell.Select</SPAN></SPAN>
Calendar1.Visible = False</SPAN></SPAN>

End Sub</SPAN></SPAN>

Private Sub Calendar2_Click()</SPAN></SPAN>
ActiveCell.Value = CDbl(Calendar2.Value)</SPAN></SPAN>
ActiveCell.NumberFormat = "mm/dd/yyyy"</SPAN></SPAN>
ActiveCell.Select</SPAN></SPAN>
Calendar2.Visible = False</SPAN></SPAN>

End Sub</SPAN></SPAN>

Private Sub Calendar3_Click()</SPAN></SPAN>
ActiveCell.Value = CDbl(Calendar3.Value)</SPAN></SPAN>
ActiveCell.NumberFormat = "mm/dd/yyyy"</SPAN></SPAN>
ActiveCell.Select</SPAN></SPAN>
Calendar3.Visible = False</SPAN></SPAN>

End Sub</SPAN></SPAN>

Private Sub Worksheet_SelectionChange(ByVal Target As Range)</SPAN></SPAN>

If Target.Cells.Count > 1 Then Exit Sub</SPAN></SPAN>
If Not Application.Intersect(Range("J8"), Target) Is Nothing Then</SPAN></SPAN>
Calendar1.Left = Target.Left + Target.Width - Calendar1.Width</SPAN></SPAN>
Calendar1.Top = Target.Top + Target.Height</SPAN></SPAN>
Calendar1.Visible = True</SPAN></SPAN>
' select Today's date in the Calendar</SPAN></SPAN>
Calendar1.Value = Date</SPAN></SPAN>
ElseIf Calendar1.Visible Then Calendar1.Visible = False</SPAN></SPAN>
End If</SPAN></SPAN>
If Target.Cells.Count > 1 Then Exit Sub</SPAN></SPAN>
If Not Application.Intersect(Range("J10"), Target) Is Nothing Then</SPAN></SPAN>
Calendar2.Left = Target.Left + Target.Width - Calendar2.Width</SPAN></SPAN>
Calendar2.Top = Target.Top + Target.Height</SPAN></SPAN>
Calendar2.Visible = True</SPAN></SPAN>
' select Today's date in the Calendar</SPAN></SPAN>
Calendar2.Value = Date</SPAN></SPAN>
ElseIf Calendar2.Visible Then Calendar2.Visible = False</SPAN></SPAN>
End If</SPAN></SPAN>
If Target.Cells.Count > 1 Then Exit Sub</SPAN></SPAN>
If Not Application.Intersect(Range("J12"), Target) Is Nothing Then</SPAN></SPAN>
Calendar3.Left = Target.Left + Target.Width - Calendar3.Width</SPAN></SPAN>
Calendar3.Top = Target.Top + Target.Height</SPAN></SPAN>
Calendar3.Visible = True</SPAN></SPAN>
' select Today's date in the Calendar</SPAN></SPAN>
Calendar3.Value = Date</SPAN></SPAN>
ElseIf Calendar3.Visible Then Calendar3.Visible = False</SPAN></SPAN>
End If</SPAN></SPAN>




Dim str As String</SPAN></SPAN>
Dim cboTemp As OLEObject</SPAN></SPAN>
Dim ws As Worksheet</SPAN></SPAN>
Set ws = ActiveSheet</SPAN></SPAN>
Application.EnableEvents = False</SPAN></SPAN>
Application.ScreenUpdating = True</SPAN></SPAN>

If Application.CutCopyMode Then</SPAN></SPAN>
'allow copying and pasting on the worksheet</SPAN></SPAN>
GoTo errHandler</SPAN></SPAN>
End If</SPAN></SPAN>

Set cboTemp = ws.OLEObjects("areacombo")</SPAN></SPAN>
On Error Resume Next</SPAN></SPAN>
With cboTemp</SPAN></SPAN>
.Top = 10</SPAN></SPAN>
.Left = 10</SPAN></SPAN>
.Width = 50</SPAN></SPAN>
.ListFillRange = ""</SPAN></SPAN>
.LinkedCell = ""</SPAN></SPAN>
.Visible = False</SPAN></SPAN>
.Value = ""</SPAN></SPAN>
End With</SPAN></SPAN>

errHandler:</SPAN></SPAN>
Application.EnableEvents = True</SPAN></SPAN>
Exit Sub</SPAN></SPAN>

End Sub</SPAN></SPAN>
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,214,935
Messages
6,122,337
Members
449,078
Latest member
skydd

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