carcharoth2554
New Member
- Joined
- Feb 5, 2013
- Messages
- 30
Hi guys,
Win 7 64bit Excel 2010
I have grapppled with with one for a while now and through direction ended up finding a nifty piece of code that overlays a combobox onto your validation list when double clicked; very useful. When I went to integrate this code into a second worksheet I found that the combobox fails ("TempCombo" still appears but loads no data options) when the data validation list is based on data in another worksheet. I really do not want to load all of the options directly into the validation list as I like to keep my data dynamic and easy to use for my colleagues. Could somebody please take a shot at solving this? I think it is something simple on the top level effecting visibility but can't for the life of me get my head around it.
Thanks!!
Referenced code: Excel Data Validation Combo box
Win 7 64bit Excel 2010
I have grapppled with with one for a while now and through direction ended up finding a nifty piece of code that overlays a combobox onto your validation list when double clicked; very useful. When I went to integrate this code into a second worksheet I found that the combobox fails ("TempCombo" still appears but loads no data options) when the data validation list is based on data in another worksheet. I really do not want to load all of the options directly into the validation list as I like to keep my data dynamic and easy to use for my colleagues. Could somebody please take a shot at solving this? I think it is something simple on the top level effecting visibility but can't for the life of me get my head around it.
Thanks!!
Referenced code: Excel Data Validation Combo box
Code:
'==========================
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
Dim str As String
Dim cboTemp As OLEObject
Dim ws As Worksheet
Set ws = ActiveSheet
Cancel = True
Set cboTemp = ws.OLEObjects("TempCombo")
On Error Resume Next
With cboTemp
'clear and hide the combo box
.ListFillRange = ""
.LinkedCell = ""
.Visible = False
End With
On Error GoTo errHandler
If Target.Validation.Type = 3 Then
'if the cell contains a data validation list
Application.EnableEvents = False
'get the data validation formula
str = Target.Validation.Formula1
str = Right(str, Len(str) - 1)
With cboTemp
'show the combobox with the list
.Visible = True
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width + 5
.Height = Target.Height + 5
.ListFillRange = ws.Range(str).Address
.LinkedCell = Target.Address
End With
cboTemp.Activate
'open the drop down list automatically
Me.TempCombo.DropDown
End If
errHandler:
Application.EnableEvents = True
Exit Sub
End Sub
'=========================================
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim str As String
Dim cboTemp As OLEObject
Dim ws As Worksheet
Set ws = ActiveSheet
Set cboTemp = ws.OLEObjects("TempCombo")
On Error Resume Next
If cboTemp.Visible = True Then
With cboTemp
.Top = 10
.Left = 10
.ListFillRange = ""
.LinkedCell = ""
.Visible = False
.Value = ""
End With
End If
errHandler:
Application.EnableEvents = True
Exit Sub
End Sub