VBA QUESTION, dependant combobox on another combobox in Userform

Kyletok

New Member
Joined
Sep 16, 2017
Messages
47
I tried to google this, but didn't know how to word it properly so couldn't find a proper non complicated solution.

I have a table called 'Accounts' with all the account information.
Right now when I open the userform I have:

Code:
Private Sub UserForm_Initialize()
AccountBox.List = [Accounts].Columns(2).Value
End Sub

Which loads it with all the account numbers.

What if I had a combobox above it for Vendor?
Code:
VendorBox.List = [Accounts].Columns(1).Value

Can I somehow only show the accounts for the chosen vendor in AccountBox?
(I feel I am wording this wrong, can I filter it so it only shows the rows with the vendor?)
 
How about
Code:
Private Sub UserForm_Initialize()
   Dim i As Long
   Dim Cl As Range
   
   For Each Cl In [Accounts].Columns(4).Rows
      If Cl.Value = "Name" Then
         Me.ComboBox1.AddItem Cl.Offset(, -3).Value
         Me.ComboBox1.column(1, i) = Cl.Offset(, -2).Value
         i = i + 1
      End If
   Next Cl
End Sub
 
Upvote 0

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
How about
Code:
Private Sub UserForm_Initialize()
   Dim i As Long
   Dim Cl As Range
   
   For Each Cl In [Accounts].Columns(4).Rows
      If Cl.Value = "Name" Then
         Me.ComboBox1.AddItem Cl.Offset(, -3).Value
         Me.ComboBox1.column(1, i) = Cl.Offset(, -2).Value
         i = i + 1
      End If
   Next Cl
End Sub
That seems to do the trick! thank you so much I am very excited to start using it.

One thing, its not really an issue but if there's a fix I'd like to put it in.
When there is only 1 entry for an Analyst the combobox will include it with the second column the way it should, but for some reason theres a horizontal scroll bar, which doesn't appear otherwise.

Thanks again for all the help, this is going to help me a lot in building our reporting tool.
 
Upvote 0
You should only get the scroll bar if the values are greater than the width of the combo.
 
Upvote 0
I don't get that, if there is a scroll bar of 1 value in the combo, there is also a scroll bar if this is more than one value.
Check that you don't have any extra spaces for the 1 value.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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