Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Adding Sheets to a combo Box

I am trying to a sheets to a combo box without knowing the number of
sheets. I have tried this code:

For Each Sheet in ThisWorkBook
cmbComboBox1.AddItem Sheet.Name
Next

Any Ideas. Thanks
-David

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Adding Sheets to a combo Box

Sorry thats add sheets to a combo box

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Adding Sheets to a combo Box

this should work

Sub test()

Dim SH As Worksheet
For Each SH In Worksheets
i = i + 1
ComboBox1.AddItem "test" & SH.Name
Next
End Sub


--


Gary


"David Pick" wrote in message
oups.com...
I am trying to a sheets to a combo box without knowing the number of
sheets. I have tried this code:

For Each Sheet in ThisWorkBook
cmbComboBox1.AddItem Sheet.Name
Next

Any Ideas. Thanks
-David



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Adding Sheets to a combo Box

you can get rid of the i=i+1 line, it was leftover from something else

--


Gary


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
this should work

Sub test()

Dim SH As Worksheet
For Each SH In Worksheets
i = i + 1
ComboBox1.AddItem "test" & SH.Name
Next
End Sub


--


Gary


"David Pick" wrote in message
oups.com...
I am trying to a sheets to a combo box without knowing the number of
sheets. I have tried this code:

For Each Sheet in ThisWorkBook
cmbComboBox1.AddItem Sheet.Name
Next

Any Ideas. Thanks
-David





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Adding Sheets to a combo Box

Thanks Gary that worked perfectly.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Adding Sheets to a combo Box

David,

A combo box can be added to a user form or a sheet.
On a userform, the code would be "UserForm1.cmbComboBox1.AddItem Sheet.Name
On a sheet there are two types of combo boxes you can add.
One from the forms toolbar...
One from the Control tool box...

It appears you have the second choice.
As it is with the above example, you have to tell Excel
where the control is. So if the code is in the module
belonging to the sheet holding the combobox, the code would be...
Me.ComboBox1.AddItem.AddItem Sheet.Name
-or-
If the code is in a standard module the code would be...
Worksheets("Sheet1").ComboBox1.AddItem Sheet.Name

Also, you would have a little cleaner code if you used a different
variable name for sheet...maybe "Sht".

Regards,
Jim Cone
San Francisco, USA


"David Pick" wrote in message oups.com...
I am trying to a sheets to a combo box without knowing the number of
sheets. I have tried this code:

For Each Sheet in ThisWorkBook
cmbComboBox1.AddItem Sheet.Name
Next

Any Ideas. Thanks
-David

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Adding Sheets to a combo Box

correction...
Me.ComboBox1.AddItem.AddItem Sheet.Name
should be...
Me.ComboBox1.AddItem Sheet.Name

Jim Cone
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
combo function of adding % jenn Excel Worksheet Functions 2 November 3rd 09 11:44 PM
Adding/Saving Combo Additems 10_a_c Excel Worksheet Functions 0 March 14th 07 12:10 PM
Adding database data to a combo box... Lyndon Excel Discussion (Misc queries) 1 July 27th 05 10:42 AM
adding into combo box and removing duplicates Abhay Sanan Excel Programming 1 June 1st 05 05:05 PM
adding info to combo box JT[_2_] Excel Programming 0 February 17th 05 11:04 PM


All times are GMT +1. The time now is 01:14 PM.

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

About Us

"It's about Microsoft Excel"