Auto Populate Combobox based on Userform Text Box

Guard913

Board Regular
Joined
Apr 10, 2016
Messages
144
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
This is userform initialize only works if text is already in the code to pull

With ComboBox10
.AddItem = "1"
.AddItem = "2"
End With

However, as i make edits to the same userform but in a different text box I need the combobox to auto update to just show the items from a certain set of textboxs.

While this next code, does not work at all, I am only putting it here to help show you what i want.

With ComboBox10
.AddItem = (New_Order_Renewal.TextBox87.Value)
.AddItem = (New_Order_Renewal.TextBox90.Value)
End With

So, as TextBox87 is change (Hundreds of Options) Combobox10 updates so that once I click on it it will show TextBox87 in the dropdown for me to select, along with TextBox90 if I had put anything in it.

With this I will build and if/then statement. So that based on which option I choose, it will fill another set of textboxes with data from other textboxes previously filled. (And yes, my form has 90+ textboxes/comboboxes and other things)

How would I do all this?
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
I'm not sure where you put the code to make the combobox adjust its list automatically, maybe in "Private Sub ComboBox10_Enter()". But try this:
VBA Code:
With ComboBox10
    .Clear
    .AddItem (New_Order_Renewal.TextBox87.Value)
    .AddItem (New_Order_Renewal.TextBox90.Value)
End With

The .Clear is to clear the previous list.
 
Upvote 0
The thing is the code I put is the same as the code you put, and it does not work (i said as much in my first post).... It would be a whole new code.... I just need a code, even if not automatic, that will allow me to use a texbox value in userform to add more to combobox inside userform. I only shared the code you used in the hopes that you would understand where i was trying to go.

If I fill textbox 1 with A and then textbox 2 with B, then the Combobox either automatically or based on calling it via another macro will add text in textbox 1 & textbox 2 to the Combobox List. (It does not need to keep adding everytime a change is made, there would only ever be 2 options to choose from.

Combobox Option 1 = A (which was pulled from textbox 1)
Combobox Option 2 = B (which was pulled from textbox 2)

If I go back and change textbox 1 to C and textbox 2 to D then the new options would be as follows:

Combobox Option 1 = C (which was pulled from textbox 1)
Combobox Option 2 = D (which was pulled from textbox 2)

No More than 2 Options show at 1 time.
 
Upvote 0
The thing is the code I put is the same as the code you put,
Are you sure? your code has "=" in it, mine doesn't.
(It does not need to keep adding everytime a change is made, there would only ever be 2 options to choose from.
As a I said:
The .Clear is to clear the previous list.
So it won't add the list but replace the list.
 
Upvote 0
It should be:
VBA Code:
Private Sub CommandButton19_Click()
With ComboBox10
    .Clear
    .AddItem (New_Order_Renewal.TextBox87.Value)
    .AddItem (New_Order_Renewal.TextBox90.Value)

End With
End Sub

or it's simpler to just use "Me." to qualify the userform :

Code:
Private Sub CommandButton19_Click()
With ComboBox10
    .Clear
    .AddItem Me.TextBox87.Value
    .AddItem Me.TextBox90.Value

End With
End Sub
 
Upvote 0
yea, after i posted my response I saw what i did wrong and fixed it per your suggestion!! So HAPPY!!!! Been working on this for the last 12 hours, and have at least 24+ hours into it..... lol and still have like 8 more forms to make... Thank you for your help!!
 
Upvote 0
You're welcome, glad to help, & thanks for the feedback.:)
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,053
Latest member
Mesh

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