G0DSL3FTHAND
New Member
- Joined
- Nov 20, 2018
- Messages
- 1
Hello All,
I have a independent combobox and a dependent combobox, the dependent combobox depends on the information provided in the first independent combobox.
I know there is the select case to make fill the dependent combobox. Here is a brief overview what my code does.
I have two different user forms one for new materials and the second is for existing materials. The new material user form populates the storage sheet with the different materials. the material information comes in two forms a 4 digit number and a 2 digit number. the new material form determines if the 4 digit number already exists, and if it does it adds the 2 digit number under the column with the 4 digit column information. For Example the input is 5600 and 96, if 5600 already exist then 96 is added to the column for the information containing 5600, but if 5600 is new it becomes the header of a new column and 96 is added to the new 5600 column. the new material form also defines the name for the the new column as No.5600.
The problem I am having is that the independent list is always growing, and since the independent list is always growing so is the number of cases. So i tried to use a for loop in conjunction with select case to try and have the cases always growing. however, when the code is run the dependent combobox does not have any of the information under the name listed in the independent combobox.
Here is my code:
Private Sub UserForm_Initialize()
Dim z As Integer
Dim x As Integer
Dim ws As Worksheet
Dim wss As Worksheet
Set ws = Sheets("Storage")
Set wss = Sheets("Staging")
Me.myctl5.AddItem "Static Preload"
Me.myctl5.AddItem "Vertical Fatigue"
Me.myctl5.AddItem "Combination Test"
Me.myctl2.Clear
'Number of Columns with Numbers in them
ws.Range("B2").Formula = "=COUNT(A1:CC1)"
'z is the column location offset by one
z = ws.Range("B2").Value + 1
For x = 3 To z
Select Case myctl1
Case ws.Cells(1, z).Value
RowSource = "No." & ws.Cells(1, z).Value
End Select
Next
End Sub
Example table:
[TABLE="width: 500"]
<tbody>[TR]
[TD]4 digit[/TD]
[TD]4546[/TD]
[TD]5600[/TD]
[TD]5400[/TD]
[TD]4500[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4546[/TD]
[TD]12[/TD]
[TD]32[/TD]
[TD]54[/TD]
[TD]58
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5600[/TD]
[TD]15[/TD]
[TD]56[/TD]
[TD]65[/TD]
[TD]25[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5400[/TD]
[TD]32[/TD]
[TD]54[/TD]
[TD]22[/TD]
[TD]55[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4500[/TD]
[TD][/TD]
[TD]96[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
I have a independent combobox and a dependent combobox, the dependent combobox depends on the information provided in the first independent combobox.
I know there is the select case to make fill the dependent combobox. Here is a brief overview what my code does.
I have two different user forms one for new materials and the second is for existing materials. The new material user form populates the storage sheet with the different materials. the material information comes in two forms a 4 digit number and a 2 digit number. the new material form determines if the 4 digit number already exists, and if it does it adds the 2 digit number under the column with the 4 digit column information. For Example the input is 5600 and 96, if 5600 already exist then 96 is added to the column for the information containing 5600, but if 5600 is new it becomes the header of a new column and 96 is added to the new 5600 column. the new material form also defines the name for the the new column as No.5600.
The problem I am having is that the independent list is always growing, and since the independent list is always growing so is the number of cases. So i tried to use a for loop in conjunction with select case to try and have the cases always growing. however, when the code is run the dependent combobox does not have any of the information under the name listed in the independent combobox.
Here is my code:
Private Sub UserForm_Initialize()
Dim z As Integer
Dim x As Integer
Dim ws As Worksheet
Dim wss As Worksheet
Set ws = Sheets("Storage")
Set wss = Sheets("Staging")
Me.myctl5.AddItem "Static Preload"
Me.myctl5.AddItem "Vertical Fatigue"
Me.myctl5.AddItem "Combination Test"
Me.myctl2.Clear
'Number of Columns with Numbers in them
ws.Range("B2").Formula = "=COUNT(A1:CC1)"
'z is the column location offset by one
z = ws.Range("B2").Value + 1
For x = 3 To z
Select Case myctl1
Case ws.Cells(1, z).Value
RowSource = "No." & ws.Cells(1, z).Value
End Select
Next
End Sub
Example table:
[TABLE="width: 500"]
<tbody>[TR]
[TD]4 digit[/TD]
[TD]4546[/TD]
[TD]5600[/TD]
[TD]5400[/TD]
[TD]4500[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4546[/TD]
[TD]12[/TD]
[TD]32[/TD]
[TD]54[/TD]
[TD]58
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5600[/TD]
[TD]15[/TD]
[TD]56[/TD]
[TD]65[/TD]
[TD]25[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5400[/TD]
[TD]32[/TD]
[TD]54[/TD]
[TD]22[/TD]
[TD]55[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4500[/TD]
[TD][/TD]
[TD]96[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]