Populating a combo box

easybpw

Active Member
Joined
Sep 30, 2003
Messages
437
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
Hi everyone! I appreciate all the help everyone offers. This is by far the best forums around!

My question is I am trying to populate a combo box with a list of customers that are found in column A of sheet 2 of the workbook. I have a userform set up already but do not know the first thing about populating the combo box. I have read many posts on here and even though they seem very similiar I can not understand what to do. What is suppose to happen is from the userform I select the customer I want, then along with the customer and the data I have inputed it would go to the appropriate cells in sheet 1. Well most of that works for me but I can't get the combo box to populate with my customer list. Any ideas?

Bill
 
Why thank you! I will check out your file. Yes I am finding there are lots of ways to do this too. It can all be very confusing!

Bill
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
If your source range is dynamic, that is if the last row of data changes from time to time on sheet 2 but begins in cell A1 and goes to A whatever, this code would accommodate that:

Private Sub UserForm_Initialize()
Dim x As Worksheet, i As Integer
Set x = Worksheets("Sheet2")
i = 1
With ComboBox1
.Clear
Do Until IsEmpty(x.Cells(i, 1))
.AddItem (x.Cells(i, 1))
i = i + 1
Loop
End With
End Sub

How can this be adapted to make use of multiple columns. Say there are 10 combo boxes, and the options for each of the 10 is spread over 10 columns. I ammended i=2 to make way for a header row and that works fine, but if I add x.Cells(i, 2) instead of x.Cells(i, 1), then the list starts from row 6 - not what I am after.

What's the best way of combining this code?
 
Upvote 0
OK...jumped the gun and tried the third option which specified a range. The code seems to be set up for only one range as everytime I add another range, I get an error. Thisi s my modified code, but I get a duplicate declaration error. I put each example into a With to try and prevent this but....well..... I dunno. I am crap at VBA.

Code:
With cboTreatment
Dim cell As Range
For Each cell In Sheets("DataOptions").Range("A2:A30")
If Not IsEmpty(cell) Then cboTreatment.AddItem cell
Next cell
End With

With cboIfFET
Dim cell As Range
For Each cell In Sheets("DataOptions").Range("B2:B30")
If Not IsEmpty(cell) Then cboIfFET.AddItem cell
Next cell
End With
 
Upvote 0

Forum statistics

Threads
1,216,030
Messages
6,128,413
Members
449,449
Latest member
Quiet_Nectarine_

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