VBA Command Button Query

Airwilf

New Member
Joined
Nov 18, 2010
Messages
1
Im fairly new to VBA so apologies for any ridiculous looking script. Basically I was asked to create a room plan for the office i work in. I have done this using Excel 07 VBA. I have a userform with a button for each desk, when a button is clicked it gets the details from 6 different combo boxes and shows the details of that desk in a textbox.Each button is named the number of the desk i.e 1,2,3....upto 87.

Everything works fine, although i have had to put the following code under each button_click function

Private Sub CommandButton9_Click()
ComboBox1.ListIndex = 8
ComboBox2.ListIndex = 8
ComboBox3.ListIndex = 8
ComboBox4.ListIndex = 8
ComboBox5.ListIndex = 8
ComboBox6.ListIndex = 8
TextBox2.Value = "Desk = " & ComboBox1.Value & vbCr & "User = " & ComboBox2.Value & vbCr & "User ID =" & ComboBox6.Value & vbCr & "Telephone Port = " & ComboBox3.Value & vbCr & "Extension = " & ComboBox4.Value & vbCr & "Network Port = " & ComboBox5.Value

so i have the above 87 times. Each time changing the list index so button 1 listindex = 0 button 2 = 1 etc.

What i would like is the above code to be written once and the listindex changes according to what button is clicked. I have checked various forums/threads but cant find an answer

Thanks in advance
<!-- / message --><!-- BEGIN TEMPLATE: ad_showthread_firstpost_sig --><!-- END TEMPLATE: ad_showthread_firstpost_sig -->
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,215,581
Messages
6,125,656
Members
449,247
Latest member
wingedshoes

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