Accessing Change or OnExit event for Commbo box added at run time

spendloa

Board Regular
Joined
Jan 28, 2003
Messages
62
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
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,224,542
Messages
6,179,421
Members
452,913
Latest member
JWD210

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