Userform to show only specific data in combobox dependant on other combobox selection

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,736
Office Version
  1. 2007
Platform
  1. Windows
Hi,
I have a userform with various comboboxes.
Ther 2 comboboxes in question are as follows.

ComboBox3 of which is MAKE comprising of "HONDA" "KAWASAKI" "YAMAHA" & are the values in drop down list
This is Table 1

ComboBox8 of which is ORIGINAL PART NUMBERS comprising of ALL part number for all the makes mentioned above currently say 20 of them
Currently this is Table 6

So example of what i would like to do.
If HONDA is selected in ComboBox3 then only show the honda part numbers in ComboBox8

So i assume that i need new tables for each make so i have now done that.
HONDA is Table 9
KAWASAKI is Table 10
YAMAHA is Table 11

Later i will be adding more but for now can you advise how i write the code for ComboBox8

Example
If HONDA is selected only show Table 9 results
ELSE
If KAWASAKI is selected only show Table 10 result
ELSE
If YAMAHA is selected only show Table 11 result


Many thanks
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Thanks,but i think it needs to be done something like this

Rich (BB code):
Private Sub ComboBox8_Change()
If ComboBox3.Value = "HONDA" Then
Table9.Show
Else
If ComboBox3.Value = "KAWASAKI" Then
Table10.Show
Else
If ComboBox3.Value = "YAMAHA" Then
Table11.Show
eN DIF
End Sub
 
Upvote 0
I think you are correct sorry.
Just need to see how to do it

Thanks
 
Upvote 0
Hi,
assuming that your data is listed in Tables (not ranges) all on same sheet like example below, then suggest that you first give each table a meaningful name that reflects the values in your ComboBox3 list with the added suffix Table mainly to identify them as tables.

Combobox3 Values
Honda
Kawasaki
Yamaha

The Table Names would be

HondaTable
KawasakiTable
YamahaTable


and so on

Place this code in your userforms code page

Rich (BB code):
Private Sub ComboBox3_Change()
    Dim wsListTables  As Worksheet
    Dim tbl           As ListObject
    Dim whichtable    As String
   
    whichtable = Me.ComboBox3.Value
    If Len(whichtable) = 0 Then Exit Sub
   
      'set object variable to combobox parts tables worksheet
    Set wsListTables = ThisWorkbook.Worksheets("Parts Tables")
   
    Set tbl = wsListTables.ListObjects(whichtable & "table")
   
    Me.ComboBox8.List = tbl.DataBodyRange.Value
   
End Sub

Change the name of parts tables worksheet as required

Dave




07-01-2023.xls
ABCDE
1HondaKAWASAKIYAMAHA
2HON Part1KW Part1YAM Part1
3HON Part2KW Part2YAM Part2
4HON Part3KW Part3YAM Part3
5HON Part4KW Part4YAM Part4
6HON Part6KW Part6YAM Part6
7HON Part5KW Part5YAM Part5
8HON Part7KW Part7YAM Part7
Parts Tables
 
Upvote 0
Hi,
I have this now in place.
The worksheet where the tables are is called DATABASE
I see now values in CB3 or CB8

Previously i had RowSource in CB properties, was i right to remove that now ?

Rich (BB code):
Private Sub ComboBox3_Change()
    Dim wsListTables  As Worksheet
    Dim tbl           As ListObject
    Dim whichtable    As String
    
    whichtable = Me.ComboBox3.Value
    If Len(whichtable) = 0 Then Exit Sub
    
      'set object variable to combobox parts tables worksheet
    Set wsListTables = ThisWorkbook.Worksheets("DATABASE")
    
    Set tbl = wsListTables.ListObjects(whichtable & "table")
    
    Me.ComboBox8.List = tbl.DataBodyRange.Value

End Sub
 
Upvote 0
Putting row source back in propertis i now see it working.

Thanks
 
Upvote 0
I have little grasp of tables in Excel but I won't say that about a true database. So I think I'll bow out as I'll never use whatever I could learn about that.
In a db, this would be 1 tbl for Make, 1 for parts, and a junction table for parts/make. Hope you get a solution.
 
Upvote 0
Hi,
assuming that your data is listed in Tables (not ranges) all on same sheet like example below, then suggest that you first give each table a meaningful name that reflects the values in your ComboBox3 list with the added suffix Table mainly to identify them as tables.

Combobox3 Values
Honda
Kawasaki
Yamaha

The Table Names would be

HondaTable
KawasakiTable
YamahaTable


and so on

Place this code in your userforms code page

Rich (BB code):
Private Sub ComboBox3_Change()
    Dim wsListTables  As Worksheet
    Dim tbl           As ListObject
    Dim whichtable    As String
  
    whichtable = Me.ComboBox3.Value
    If Len(whichtable) = 0 Then Exit Sub
  
      'set object variable to combobox parts tables worksheet
    Set wsListTables = ThisWorkbook.Worksheets("Parts Tables")
  
    Set tbl = wsListTables.ListObjects(whichtable & "table")
  
    Me.ComboBox8.List = tbl.DataBodyRange.Value
  
End Sub

Change the name of parts tables worksheet as required

Dave




07-01-2023.xls
ABCDE
1HondaKAWASAKIYAMAHA
2HON Part1KW Part1YAM Part1
3HON Part2KW Part2YAM Part2
4HON Part3KW Part3YAM Part3
5HON Part4KW Part4YAM Part4
6HON Part6KW Part6YAM Part6
7HON Part5KW Part5YAM Part5
8HON Part7KW Part7YAM Part7
Parts Tables


This was very good & wondering if you could go one step further please.

Using the same Combobox3 values can we ALSO populate Combobox4 with MODELS
It makes sense to now not only load part numbers but also models.
The table will still be on the same worksheet.
Tables will be names like so,
HondaModels
KawasakiModels
YamahaModels

Thanks.
 
Upvote 0
Would it be like this ?

VBA Code:
Private Sub ComboBox3_Change()
    Dim wsListTables  As Worksheet
    Dim tbl           As ListObject
    Dim whichtable    As String
 
    whichtable = Me.ComboBox3.Value
    If Len(whichtable) = 0 Then Exit Sub
 
    Set wsListTables = ThisWorkbook.Worksheets("DATABASE")
 
    Set tbl = wsListTables.ListObjects(whichtable & "table")
 
    Me.ComboBox8.List = tbl.DataBodyRange.Value
    Me.ComboBox4.List = tbl.DataBodyRange.Value
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

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