Populating my combo box

rharri1972

Board Regular
Joined
Nov 12, 2021
Messages
132
Office Version
  1. 2019
Platform
  1. Windows
Hello! First off, thank you all for lending your knowledge to help those of us that lack in that knowledge. I am so thankful to be able to ask how to complete a needed task and through your teaching or showing I am able to learn by this. Sometimes it just doesn't sink in like it maybe would have when i was younger.

My need at this moment is to populate ComboBox 1 on userform 3. I have a worksheet "Customers Select" and the range is A2:G464 at the moment but will be adding additional customers or rows to this worksheet as I gain more customers.

My hope is to use the combobox on a userform that will be an order form. On the drop down I would like to see my list of customers so I can select the correct one for the current order being placed.

Again, i would like for this to be dynamic so as my worksheet rows grow, the combobox will update accordingly.

Here is the code i currently have that just doesn't work. As matter of fact it returns Can't set rowsource property. Invalid property value.

Me.ComboBox1.RowSource = "Customers Select!A2:G" & Range("G" & Rows.Count).End(xlUp).Row

I have this code set in the userform and the event is on initialize.

I have no code set within the combobox.

again, any help is greatly appreciated.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try this:
VBA Code:
Private Sub CommandButton1_Click()
'Modified  7/17/2022  11:10:55 AM  EDT
Dim r As Range
ComboBox1.Clear
Dim Lastrow As Long
    With Sheets("Customers")
        Lastrow = .Cells(Rows.Count, "A").End(xlUp).Row

            For Each r In .Range("A2:G" & Lastrow)
                ComboBox1.AddItem r.Value
            Next
    End With
End Sub
 
Upvote 0
Try this:
VBA Code:
Private Sub CommandButton1_Click()
'Modified  7/17/2022  11:10:55 AM  EDT
Dim r As Range
ComboBox1.Clear
Dim Lastrow As Long
    With Sheets("Customers")
        Lastrow = .Cells(Rows.Count, "A").End(xlUp).Row

            For Each r In .Range("A2:G" & Lastrow)
                ComboBox1.AddItem r.Value
            Next
    End With
End Sub
My Answer is this...can I do this on Userform Initialize? I need this information before hitting any button.
 
Upvote 0
Try this:
VBA Code:
Private Sub UserForm_Initialize()
'Modified  7/17/2022  11:55:00 AM  EDT
Dim r As Range
ComboBox1.Clear
Dim Lastrow As Long
    With Sheets("Customers")
        Lastrow = .Cells(Rows.Count, "A").End(xlUp).Row

            For Each r In .Range("A2:G" & Lastrow)
                ComboBox1.AddItem r.Value
            Next
    End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,843
Members
452,948
Latest member
UsmanAli786

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