Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default create a second combo box from a first combo box

How do I create a second combo box, from a first one? I am trying to make a
hierarchical sheet listing, so the first box has file names, and the second
should show sheet names. I am passing the top, left, width and height, to
offset the position of the second box, and the name of the first so I can
name the second one, modifying the name to reflect that it is a 'sub' box.
For example, if the first is named,"Simpsons", I would like the second to be
named "SimpsonsSub". I do not want the second box present unless a choice is
made from the first box. Is this possible?

Wazooli
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default create a second combo box from a first combo box

Recording a macro while adding a combobox provides this code

ActiveSheet.OLEObjects.Add(ClassType:="Forms.Combo Box.1", Link:=False, _
DisplayAsIcon:=False, Left:=201, Top:=229.5, Width:=71.25, Height:=
_
16.5).Select

so you could do

Private Sub Simpsons_Click()
Dim cb As MsForms.ComboBox
Dim obj1 As OLEObject
Dim obj As OLEObject
On Error Resume Next
ActiveSheet.OLEObjects("SimpsonsSub").Delete
On Error GoTo 0
Set obj1 = ActiveSheet.OLEObjects("Simpsons")
Set obj = ActiveSheet.OLEObjects.Add( _
ClassType:="Forms.ComboBox.1", _
Link:=False, _
DisplayAsIcon:=False, _
Left:=obj1.Left + obj1.Width + 5, _
Top:=obj1.Top, _
Width:=obj1.Width, _
Height:=obj1.Height)
Set cb = obj.Object
cb.Name = "SimpsonsSub"
End Sub

You would then need to fill it based on the selection in Simpsons

Not sure how you want to trigger a deletion. But use code as shown since I
delete any existing box to avoid duplicates.

If you want to create event code for it, you can look at Chip Pearson's site
http://www.cpearson.com/excel/vbe.htm

--
Regards,
Tom Ogilvy




"Wazooli" wrote in message
...
How do I create a second combo box, from a first one? I am trying to make

a
hierarchical sheet listing, so the first box has file names, and the

second
should show sheet names. I am passing the top, left, width and height, to
offset the position of the second box, and the name of the first so I can
name the second one, modifying the name to reflect that it is a 'sub' box.
For example, if the first is named,"Simpsons", I would like the second to

be
named "SimpsonsSub". I do not want the second box present unless a choice

is
made from the first box. Is this possible?

Wazooli



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default create a second combo box from a first combo box

perfect -thanks tom

"Tom Ogilvy" wrote:

Recording a macro while adding a combobox provides this code

ActiveSheet.OLEObjects.Add(ClassType:="Forms.Combo Box.1", Link:=False, _
DisplayAsIcon:=False, Left:=201, Top:=229.5, Width:=71.25, Height:=
_
16.5).Select

so you could do

Private Sub Simpsons_Click()
Dim cb As MsForms.ComboBox
Dim obj1 As OLEObject
Dim obj As OLEObject
On Error Resume Next
ActiveSheet.OLEObjects("SimpsonsSub").Delete
On Error GoTo 0
Set obj1 = ActiveSheet.OLEObjects("Simpsons")
Set obj = ActiveSheet.OLEObjects.Add( _
ClassType:="Forms.ComboBox.1", _
Link:=False, _
DisplayAsIcon:=False, _
Left:=obj1.Left + obj1.Width + 5, _
Top:=obj1.Top, _
Width:=obj1.Width, _
Height:=obj1.Height)
Set cb = obj.Object
cb.Name = "SimpsonsSub"
End Sub

You would then need to fill it based on the selection in Simpsons

Not sure how you want to trigger a deletion. But use code as shown since I
delete any existing box to avoid duplicates.

If you want to create event code for it, you can look at Chip Pearson's site
http://www.cpearson.com/excel/vbe.htm

--
Regards,
Tom Ogilvy




"Wazooli" wrote in message
...
How do I create a second combo box, from a first one? I am trying to make

a
hierarchical sheet listing, so the first box has file names, and the

second
should show sheet names. I am passing the top, left, width and height, to
offset the position of the second box, and the name of the first so I can
name the second one, modifying the name to reflect that it is a 'sub' box.
For example, if the first is named,"Simpsons", I would like the second to

be
named "SimpsonsSub". I do not want the second box present unless a choice

is
made from the first box. Is this possible?

Wazooli




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
How do I create a combo box that is tied to another combo box? rosamaria Excel Worksheet Functions 2 December 9th 09 10:32 PM
linking a form combo box... results from the combo box to another Trey Excel Discussion (Misc queries) 1 July 15th 07 01:58 AM
combo reference on another combo box for picking address etc. kbjin Excel Worksheet Functions 1 December 8th 06 03:29 PM
"Combo Box - getting control combo box to stick in place in worksh ajr Excel Discussion (Misc queries) 1 February 16th 05 02:05 AM
"Combo Box - getting control combo box to stick in place in worksh ajr Excel Discussion (Misc queries) 0 February 15th 05 07:45 PM


All times are GMT +1. The time now is 03:28 AM.

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"