Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Controls names as varible?


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.


--
lily
------------------------------------------------------------------------
lily's Profile: http://www.excelforum.com/member.php...o&userid=33150
View this thread: http://www.excelforum.com/showthread...hreadid=537334

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Controls names as varible?

this page talks about using data validation which may be all you really need.
But it also has sample code on using a combobox to simulate data validation
and have more contron on the appearance of items in the list. Check it out.

Debra Dalgleish's site
http://www.contextures.com/xlDataVal10.html

--
Regards,
Tom Ogilvy


"lily" wrote:


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.


--
lily
------------------------------------------------------------------------
lily's Profile: http://www.excelforum.com/member.php...o&userid=33150
View this thread: http://www.excelforum.com/showthread...hreadid=537334


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
same varible in formula jheiser57 Excel Worksheet Functions 0 June 21st 10 04:49 PM
varible calculation kinsey New Users to Excel 7 September 30th 07 08:50 AM
varible table not spxer Excel Worksheet Functions 3 August 4th 06 05:13 PM
See names of controls TheMath Excel Discussion (Misc queries) 2 July 7th 06 06:06 PM
Cycle through controls with similar names Tim Archer[_2_] Excel Programming 1 January 27th 05 12:13 PM


All times are GMT +1. The time now is 03:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"