dhardister
New Member
- Joined
- Jun 27, 2018
- Messages
- 2
I have the following code that reveals a ComboBox when a target cell is double clicked
The problem that occurs is a third click is actually required to begin typing into the box. If I click on another worksheet tab and then back to the tab with the ComboBox, the cursor is showing in the box. You can see the remarked code near the end where I tried to accomplish this programmatically, but it doesn't work.
Have any suggestions to uncover the hidden cursor?
Code:
[FONT=Arial]Private Sub Worksheet_BeforeDoubleClick([/FONT]<wbr style="font-family: Arial, Helvetica, sans-serif;">[FONT=Arial]ByVal Target As Range, _ [/FONT]
[FONT=Arial] Cancel As Boolean) [/FONT]
[FONT=Arial]Dim str As String [/FONT]
[FONT=Arial]Dim cboTemp As OLEObject [/FONT]
[FONT=Arial]Dim ws As Worksheet [/FONT]
[FONT=Arial]Set ws = ActiveSheet [/FONT]
[FONT=Arial]Set cboTemp = ws.OLEObjects("TempCombo") [/FONT]
[FONT=Arial] On Error Resume Next [/FONT]
[FONT=Arial] With cboTemp [/FONT]
[FONT=Arial] 'clear and hide the combo box [/FONT]
[FONT=Arial] .ListFillRange = "" [/FONT]
[FONT=Arial] .LinkedCell = "" [/FONT]
[FONT=Arial] .Visible = False [/FONT]
[FONT=Arial] End With [/FONT]
[FONT=Arial]On Error GoTo errHandler [/FONT]
[FONT=Arial] If Target.Validation.Type = 3 Then [/FONT]
[FONT=Arial] 'if the cell contains a data validation list [/FONT]
[FONT=Arial] 'Cancel = True [/FONT]
[FONT=Arial] Application.EnableEvents = False [/FONT]
[FONT=Arial] 'get the data validation formula [/FONT]
[FONT=Arial] str = Target.Validation.Formula1 [/FONT]
[FONT=Arial] str = Right(str, Len(str) - 1) [/FONT]
[FONT=Arial] With cboTemp [/FONT]
[FONT=Arial] 'show the combobox with the list [/FONT]
[FONT=Arial] .Visible = True [/FONT]
[FONT=Arial] .Left = Target.Left [/FONT]
[FONT=Arial] .Top = Target.Top [/FONT]
[FONT=Arial] .Width = Target.Width + 100 [/FONT]
[FONT=Arial] .Height = Target.Height + 1 [/FONT]
[FONT=Arial] .ListFillRange = ws.Range(str).Address [/FONT]
[FONT=Arial] .LinkedCell = Target.Address [/FONT]
[FONT=Arial] End With [/FONT]
[FONT=Arial] cboTemp.Activate [/FONT]
[FONT=Arial]' Application.ScreenUpdating = False [/FONT]
[FONT=Arial]' Worksheets("Instructions").[/FONT]<wbr style="font-family: Arial, Helvetica, sans-serif;">[FONT=Arial]Activate [/FONT]
[FONT=Arial]' Application.Wait (Now + TimeValue("0:00:01")) [/FONT]
[FONT=Arial]' Worksheets("Draft_Board").[/FONT]<wbr style="font-family: Arial, Helvetica, sans-serif;">[FONT=Arial]Activate [/FONT]
[FONT=Arial] 'open the drop down list automatically [/FONT]
[FONT=Arial] 'TempCombo.DropDown [/FONT]
[FONT=Arial] End If [/FONT]
[FONT=Arial] Application.EnableEvents = True [/FONT]
[FONT=Arial] Application.ScreenUpdating = True [/FONT]
[FONT=Arial]errHandler: [/FONT]
[FONT=Arial] Application.EnableEvents = True [/FONT]
[FONT=Arial] Exit Sub [/FONT]
[FONT=Arial]End Sub [/FONT]
The problem that occurs is a third click is actually required to begin typing into the box. If I click on another worksheet tab and then back to the tab with the ComboBox, the cursor is showing in the box. You can see the remarked code near the end where I tried to accomplish this programmatically, but it doesn't work.
Have any suggestions to uncover the hidden cursor?