Combobox List Fill Range Code

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
 
Hi,
you need to ensure that the named Range for Combobox is across both columns

e.g.

Name: DayListCodes

='Demographics Options'!$B$2:$C$8


Dave
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
In design mode, check your combobox ColumnCount value is 2 & BoundColumn is 1

Dave
 
Upvote 0
Okay, I updated the column count value to 2. Now the combo box drop down is giving me both columns information but not hiding the first column. Thanks again for all of your help!
 
Upvote 0
It is working! Thank you.

One last thing if you don't mind! When I click enter, it does not move to the next cell. It is making me click out of it. Could you check this part of the code?

Code:
Option Explicit
' Developed by Contextures Inc.
' [URL="http://www.contextures.com"]www.contextures.com[/URL]
Private Sub TempCombo_KeyDown(ByVal _
        KeyCode As MSForms.ReturnInteger, _
        ByVal Shift As Integer)
    'Hide combo box and move to next cell on Enter and Tab
    Select Case KeyCode
        Case 9
            ActiveCell.Offset(0, 1).Activate
        Case 13
            ActiveCell.Offset(1, 0).Activate
        Case Else
            'do nothing
    End Select
End Sub
 
Last edited:
Upvote 0
Oh my gosh, thank you so much! It is finally working. I have been trying to get this done for two weeks. I really appreciate all your help!

That's ok glad we got there in the end

Merry Christmas

Dave
 
Upvote 0
One last thing if you don't mind! When I click enter, it does not move to the next cell. It is making me click out of it. Could you check this part of the code?


Option Explicit
' Developed by Contextures Inc.
' www.contextures.com
Private Sub TempCombo_KeyDown(ByVal _
KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
'Hide combo box and move to next cell on Enter and Tab
Select Case KeyCode
Case 9
ActiveCell.Offset(0, 1).Activate
Case 13
ActiveCell.Offset(1, 0).Activate
Case Else
'do nothing
End Select
End Sub
 
Upvote 0
If you have named your combobox differently to the published name shown in RED then you will need to update the procedure with correct name.

Rich (BB code):
Private Sub TempCombo_KeyDown(ByVal _
        KeyCode As MSForms.ReturnInteger, _
        ByVal Shift As Integer)

Dave
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,209
Members
453,022
Latest member
RobertV1609

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