Combo Box help. Struggling to get range in to it.

BigShango

Board Regular
Joined
May 8, 2014
Messages
106
Hi,

I have a combo box in a user form. I need to populate it with a list of names from my spreadsheet. The names are listed broken in to first and last name. I need them joined together in the combo box and the same on the output from it.

I really can't get my head around arrays at all. Is there a simple way for me to do this?

I'm fine with adding the names together, I just can't figure out how to put them into the combo box

I need something like

Code:
For Row = 2 to LastRow
    FirstName = Range("A" & Row)
    LastName = Range("B" & Row)
    FullName = FirstName & " " & LastName
    *FullName in to combo box list*
Next Row

I don't want to list the full names on the spreadsheet anywhere if possible. The purpose of it is that I have a whole series of individual sheets in the workbook named with the full names, I intend to use the combo box to go to the selected sheet.

I hope this makes sense. Any ideas?

Thanks
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi BigShango,

Here's two examples. The first uses the ComboBox.AddItem Method, the second uses ComboBox.List Property.

Either could be placed in your UserForm's Code module then called by UserForm_Initialize...
Code:
Sub PopulateComboBox()
 Dim lLastRow As Long, lRow As Long
 Dim sFullName As String
  
 '--clear any existing names
 Me.cboFullNames.Clear
 
 With Sheets("Sheet1")
   lLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
   For lRow = 2 To lLastRow
      sFullName = .Range("A" & lRow) & " " & Range("B" & lRow)
      
      Me.cboFullNames.AddItem (sFullName)
   Next lRow
 End With
End Sub

Code:
Sub PopulateComboBox2()
 Dim lLastRow As Long
 Dim vFullNames As Variant
 
 '--clear any existing names
 Me.cboFullNames.Clear
 
 With Sheets("Sheet1")
   lLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
   vFullNames = Evaluate( _
      .Range("A2:A" & lLastRow).Address(External:=True) _
      & "& "" "" &" & _
      .Range("B2:B" & lLastRow).Address(External:=True))
   Me.cboFullNames.List = vFullNames
 End With

End Sub

Code:
Private Sub UserForm_Initialize()
 Call PopulateComboBox2
End Sub

Modify the WorkSheet Name and ComboBox Name to match yours.
 
Upvote 0
Thanks Jerry, I'll give that a try. Also thanks for the shorter way of finding the last row!

Edit - First example works perfectly.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,549
Messages
6,120,149
Members
448,948
Latest member
spamiki

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