Fill Combobox list from a Row

g-man97

New Member
Joined
Sep 30, 2004
Messages
24
I have a table with the values for the combobox in row 2, columns 11-76. I picked up the following code to fill the combobox. Of course it fills based on the data being all in a column.


Private Sub UserForm_Initialize()
'define variable types
Dim rng As Range
Dim I As Long
Application.ScreenUpdating = False
'Active sheet where office list is
Sheets("OfficeLocations").Activate
'enter loop
For I = 2 To 67
'data is in column "B"
Set rng = ActiveSheet.Range("B" & I)
InputForm.ComboBox1.AddItem rng.Value
Next I
Sheets("MainMenu").Select
Range("G11").Select
End Sub

I'd really appreciate a suggestion / example / nudge on how to get the data for combobox from a row.

As always, thanks in advance for the suggestions.


G-Man
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Change the For loop to go from 11 to 67 (rather than 2 to 67)
Then rather than using the Range(), use Cells(). Using Cells, you can call the columns more easily by numbers (i.e. 11-67).
As long as you have the sheets and the userform named InputForm, the below works.

Private Sub UserForm_Initialize()
'define variable types
Dim rng As Range
Dim I As Long
Application.ScreenUpdating = False
'Active sheet where office list is
Sheets("OfficeLocations").Activate
'enter loop
For I = 11 To 67
'data is in column "B"
Set rng = ActiveSheet.Cells(2, I)
InputForm.ComboBox1.AddItem rng.Value
Next I
Sheets("MainMenu").Select
Range("G11").Select
End Sub
 
Upvote 0
Vconfused, thanks a million, it worked like a charm!! I'll definitely store that one away for future reference! I'm sure it'll come in handy!

Thanks again.


G-Man
 
Upvote 0

Forum statistics

Threads
1,203,455
Messages
6,055,541
Members
444,794
Latest member
HSAL

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