sarahrb1989
New Member
- Joined
- Dec 15, 2017
- Messages
- 30
I am new to using the Developer tab and Combobox's in Excel. I am working on a spreadsheet for work and want to use some code I found online. I want the combobox to pull data from multiple (dynamic, if possible) data validation lists (demographic info) on a separate sheet. The sheet I want to use the Combobox on is called, General Wait List (sheet1) and the sheet that has the demographics list options is called, demographic options (sheet3). Here is where you can find the sample file: http://www.contextures.com/excelfiles.html#DataVal
Search for the following:
DV0057 - Data Validation Combobox Codes -- Double-click a cell that contains a data validation list, and a combobox appears, showing a list of descriptions. Select a descriptions, and that descriptions numeric code is entered in the cell. Lists are stored in named ranges on a separate sheet. Excel 2007/2010 format; macros must be enabled. DataValComboboxCodes.zip 30 kb 02-May-12
I can't figure. out what range to list or code. I'm also not sure if I should be listing the range in the properties tab of the combobox itself or just edit the code. Any help would be greatly appreciated!!!
Please let me know if there is any other info needed.
Here is the portion of code I'm attempting to use:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim str As String
Dim cboTemp As OLEObject
Dim ws As Worksheet
Dim wsList As Worksheet
Set ws = ActiveSheet
Set wsList = Sheets("GENERAL WAIT LIST")
Cancel = True
Set cboTemp = ws.OLEObjects("ComboBox1")
On Error Resume Next
With cboTemp
.ListFillRange = ""
.LinkedCell = ""
.Visible = False
End With
On Error GoTo errHandler
If Target.Validation.Type = 3 Then
Application.EnableEvents = False
str = Target.Validation.Formula1
str = Right(str, Len(str) - 1)
With cboTemp
.Visible = True
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width + 15
.Height = Target.Height + 5
.ListFillRange = str & "Codes"
.LinkedCell = Target.Address
End With
cboTemp.Activate
End If
errHandler:
Application.EnableEvents = True
Exit Sub
End Sub
Search for the following:
DV0057 - Data Validation Combobox Codes -- Double-click a cell that contains a data validation list, and a combobox appears, showing a list of descriptions. Select a descriptions, and that descriptions numeric code is entered in the cell. Lists are stored in named ranges on a separate sheet. Excel 2007/2010 format; macros must be enabled. DataValComboboxCodes.zip 30 kb 02-May-12
I can't figure. out what range to list or code. I'm also not sure if I should be listing the range in the properties tab of the combobox itself or just edit the code. Any help would be greatly appreciated!!!
Please let me know if there is any other info needed.
Here is the portion of code I'm attempting to use:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim str As String
Dim cboTemp As OLEObject
Dim ws As Worksheet
Dim wsList As Worksheet
Set ws = ActiveSheet
Set wsList = Sheets("GENERAL WAIT LIST")
Cancel = True
Set cboTemp = ws.OLEObjects("ComboBox1")
On Error Resume Next
With cboTemp
.ListFillRange = ""
.LinkedCell = ""
.Visible = False
End With
On Error GoTo errHandler
If Target.Validation.Type = 3 Then
Application.EnableEvents = False
str = Target.Validation.Formula1
str = Right(str, Len(str) - 1)
With cboTemp
.Visible = True
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width + 15
.Height = Target.Height + 5
.ListFillRange = str & "Codes"
.LinkedCell = Target.Address
End With
cboTemp.Activate
End If
errHandler:
Application.EnableEvents = True
Exit Sub
End Sub