Controls names as varible?

L

lily

I have a worksheet with a command button and a combo box (with 26
items). When the command button is clicked, a new combobox is created
right at the next row of the first one by copying it. When the command
button is clicked the second time, a new combobox is created right at
the next row of the second one, as so on. My code is:

Private Sub ComboBox1_Change()
If ComboBox1.Value = "A" Then frmA.Show
If ComboBox1.Value = "B" Then frmB.Show
.....
If ComboBox1.Value = "Z" Then frmZ.Show
End Sub

Private Sub ComboBox2_Change()
If ComboBox1.Value = "A" Then frmA.Show
If ComboBox1.Value = "B" Then frmB.Show
.....
If ComboBox1.Value = "Z" Then frmZ.Show
End Sub
........
........
........
Private Sub ComboBox26_Change()
If ComboBox1.Value = "A" Then frmA.Show
If ComboBox1.Value = "B" Then frmB.Show
.....
If ComboBox1.Value = "Z" Then frmZ.Show
End Sub

_My_intention_is_to_shorten_the_above_ugly_code_to:_

Private Sub ComboBox(1 to 26)_Change()
If ComboBox1.Value = "A" Then frmA.Show
If ComboBox1.Value = "B" Then frmB.Show
.....
If ComboBox1.Value = "Z" Then frmZ.Show
End Sub

Of course, it doesn't work. Please give some ideas. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top