Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default Loading sheet names in Combobox

Hello There,

I created a active X -ComboBox (from Control Toolbox) and would like to
load it with the sheetnames in my workbook.

This code I have as worksheet code: Credits to Tom O.

Private Sub ComboBox1_Click()
Dim Sh As Worksheet
Dim sVal As String
With ComboBox1
sVal = .Text
Clear
For Each Sh In ActiveWorkbook.Sheets
If Sh.Name < "Inputs" Then
AddItem Sh.Name
End If
Next
.Value = sVal
End With
End Sub

1. =Knowing Tom... I do not dare to say that the Combo does not get
loaded ???? !
2. If we can manage to load the Combobox, I would like to write the
selection away to cell: eg. B5.

Any Help really appreciated,

Sige

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Loading sheet names in Combobox

Your taking the answer out of context. Every piece of code I write isn't a
general solution - nor is the code necessarily original - such as in this
case, where I was helping someone with code they had written. If you want
to load a combobox with the names of the sheets, I wouldn't use the click
event of the control itself. I can't say what event to use, because I don't
know the circumstances of the requirement, but in general


Dim Sh As Worksheet
With ActiveSheet.ComboBox1
For Each Sh In ActiveWorkbook.WorkSheets
.AddItem Sh.Name
Next
End With


will put the names of the sheets in combobox1 on the activesheet. loading a
combobox and making a selection in the same event is inconsistent. to write
the value, you can use the click event

Private Sub Combobox1_click()
me.Range("B5").Value = me.Combobox1.Text
End Sub

or you could just link the combobox to the cell.


--
Regards,
Tom Ogilvy


"Sige" wrote in message
oups.com...
Hello There,

I created a active X -ComboBox (from Control Toolbox) and would like to
load it with the sheetnames in my workbook.

This code I have as worksheet code: Credits to Tom O.

Private Sub ComboBox1_Click()
Dim Sh As Worksheet
Dim sVal As String
With ComboBox1
sVal = .Text
Clear
For Each Sh In ActiveWorkbook.Sheets
If Sh.Name < "Inputs" Then
AddItem Sh.Name
End If
Next
.Value = sVal
End With
End Sub

1. =Knowing Tom... I do not dare to say that the Combo does not get
loaded ???? !
2. If we can manage to load the Combobox, I would like to write the
selection away to cell: eg. B5.

Any Help really appreciated,

Sige



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Loading sheet names in Combobox


"Sige" wrote in message
oups.com...
Hello There,

I created a active X -ComboBox (from Control Toolbox) and would like to
load it with the sheetnames in my workbook.

This code I have as worksheet code: Credits to Tom O.

Private Sub ComboBox1_Click()
Dim Sh As Worksheet
Dim sVal As String
With ComboBox1
sVal = .Text
Clear
For Each Sh In ActiveWorkbook.Sheets
If Sh.Name < "Inputs" Then
AddItem Sh.Name
End If
Next
.Value = sVal
End With
End Sub

1. =Knowing Tom... I do not dare to say that the Combo does not get
loaded ???? !


Try this, it loads by clicking the dropdown arrow

Private Sub ComboBox1_DropButtonClick()
Dim Sh As Worksheet
Dim sVal As String
With ComboBox1
sVal = .Text
.Clear
For Each Sh In ActiveWorkbook.Sheets
If Sh.Name < "Inputs" Then
.AddItem Sh.Name
End If
Next
.Value = sVal
End With
End Sub

2. If we can manage to load the Combobox, I would like to write the
selection away to cell: eg. B5.


Just set the Combo's LinkedCell property to B5.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Loading sheet names in Combobox

Thank you Tom,

It was exactly what I needed!

:o) Sige

"NOSPAM" to be removed for direct mailing...

*** Sent via Developersdex http://www.developersdex.com ***
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default Loading sheet names in Combobox

Thx a lot BOB,

Like this the loading behaviour is updated every time!
Sige



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Loading sheet names in Combobox

It is, which caters for new sheets being added very simply.

--
HTH

Bob Phillips

"Sige" wrote in message
ups.com...
Thx a lot BOB,

Like this the loading behaviour is updated every time!
Sige



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
get all sheet names in comboBox of activeworkbook and export when selected ilyaskazi[_26_] Excel Programming 5 June 14th 05 02:49 PM
Loading Sheet Names into Combo Box ExcelMonkey[_156_] Excel Programming 6 September 15th 04 01:30 PM
populate combobox with sheet names David Goodall Excel Programming 3 September 12th 04 12:37 PM
populate combobox with sheet names David Goodall Excel Programming 0 September 12th 04 08:55 AM
Populating sheet names in combobox Todd Huttenstine[_2_] Excel Programming 3 December 21st 03 12:11 AM


All times are GMT +1. The time now is 09:52 AM.

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"