Hi - wondering if anyone can help with this.
I am using the following code to guess value for a combo box, depending on the value selected in the previous combobox:-
Private Sub cboIng01_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error GoTo 1
frmStartUp.cboCat01.Value = Application.WorksheetFunction.VLookup(cboIng01.Value, ThisWorkbook.Sheets("Usual Items").Range("G:H"), 2, 0)
1: Exit Sub
End Sub
Which works fine when dealing with ComboBoxes built into the design of the form to begin with.
the problem is that I am using this code to allow the user to add more comboboxes if the need them:-
Private Sub cmdAddRow_Click()
Dim myCbo As ComboBox
With frmStartUp
.Height = .Height + 24
.cmdAddRow.Top = .cmdAddRow.Top + 24
End With
Rowtop = Rowtop + 24
Rownum = Rownum + 1
Set myCbo = frmStartUp.Controls.Add("Forms.ComboBox.1", "cboIng" & Rownum)
With myCbo
.Left = 6
.Top = Rowtop
.Width = 126
End With
With ThisWorkbook.Sheets("Usual Items")
For Each c In .Range("G2:" & .Range("G2").End(xlDown).Address)
myCbo.AddItem (c.Value)
Next c
End With
Set myCbo = frmStartUp.Controls.Add("Forms.ComboBox.1", "cboCat" & Rownum)
With myCbo
.Left = 138
.Top = Rowtop
.Width = 126
End With
With ThisWorkbook.Sheets("Usual Items")
For Each c In .Range("D2:" & .Range("D2").End(xlDown).Address)
myCbo.AddItem (c.Value)
Next c
End With
End Sub
But I cant work out how to accomplish the same guessing the next function, with the new boxes I have added.
Can any one help?
Many thanks!
Al
I am using the following code to guess value for a combo box, depending on the value selected in the previous combobox:-
Private Sub cboIng01_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error GoTo 1
frmStartUp.cboCat01.Value = Application.WorksheetFunction.VLookup(cboIng01.Value, ThisWorkbook.Sheets("Usual Items").Range("G:H"), 2, 0)
1: Exit Sub
End Sub
Which works fine when dealing with ComboBoxes built into the design of the form to begin with.
the problem is that I am using this code to allow the user to add more comboboxes if the need them:-
Private Sub cmdAddRow_Click()
Dim myCbo As ComboBox
With frmStartUp
.Height = .Height + 24
.cmdAddRow.Top = .cmdAddRow.Top + 24
End With
Rowtop = Rowtop + 24
Rownum = Rownum + 1
Set myCbo = frmStartUp.Controls.Add("Forms.ComboBox.1", "cboIng" & Rownum)
With myCbo
.Left = 6
.Top = Rowtop
.Width = 126
End With
With ThisWorkbook.Sheets("Usual Items")
For Each c In .Range("G2:" & .Range("G2").End(xlDown).Address)
myCbo.AddItem (c.Value)
Next c
End With
Set myCbo = frmStartUp.Controls.Add("Forms.ComboBox.1", "cboCat" & Rownum)
With myCbo
.Left = 138
.Top = Rowtop
.Width = 126
End With
With ThisWorkbook.Sheets("Usual Items")
For Each c In .Range("D2:" & .Range("D2").End(xlDown).Address)
myCbo.AddItem (c.Value)
Next c
End With
End Sub
But I cant work out how to accomplish the same guessing the next function, with the new boxes I have added.
Can any one help?
Many thanks!
Al