Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Populate one combo box based on the selection of another combo box

How can I have have the results of a second combobox based on the selection
in the first combobox
Ex. if Ford is selelected in the car combobox the model combobox will only
list ford models

Thanks

Alex
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Populate one combo box based on the selection of another combo box

Hi Alex

One way you can do it is to use select case to load an array into the
model combobox like the code below

Private Sub ComboBoxCar_Change()
Select Case ComboBoxCar.Value 'Select case using the combobox1 _
current value
Case "ford" 'if it's ford do the code below
ComboBoxModel.List = Array("mustang", "fusion") 'load an array of
models _
to the second combobox
Case "other" 'if it's other do the code below
ComboBoxModel.List = Array("some car", "some other car") 'as above
load _ the array
End Select
ComboBoxModel.ListIndex = 0 'set the second combobox to the first
value _
which would be 0 this will remove the previous array from showing in
the list
End Sub

hope this is of some help

S


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Populate one combo box based on the selection of another combo box

What kind of ComboBoxes? On UserForm? On worksheet from Controls
Toolbox toolbar? On worksheet from Forms toolbar?

Merjet


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Populate one combo box based on the selection of another combo

I am using the Forms toolbar and working on a worksheet - I don't have much
experience using controls with Excel any help would be appreciated

Thanks

Alex

"merjet" wrote:

What kind of ComboBoxes? On UserForm? On worksheet from Controls
Toolbox toolbar? On worksheet from Forms toolbar?

Merjet



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Populate one combo box based on the selection of another combo

I get an Obeject Required error message when I your code. I am working with
controls on a worksheet


Sub DropDown2_Change()

Select Case ComboBox.xls!DropDown2.Value 'Select case using the combobox1 _
current value
Case "ford" 'if it's ford do the code below
ComboBox.xls!DropDown2.List = Array("mustang", "fusion") 'load an array of
models _ to the second combobox
Case "other" 'if it's other do the code below
ComboBox.xls!DropDown2.List = Array("some car", "some other car") 'as above
load _ the array
End Select
ComboBox.xls!DropDown2.ListIndex = 0 'set the second combobox to the first
value _ which would be 0 this will remove the previous array from showing in
the List
End Sub

"Incidental" wrote:

Hi Alex

One way you can do it is to use select case to load an array into the
model combobox like the code below

Private Sub ComboBoxCar_Change()
Select Case ComboBoxCar.Value 'Select case using the combobox1 _
current value
Case "ford" 'if it's ford do the code below
ComboBoxModel.List = Array("mustang", "fusion") 'load an array of
models _
to the second combobox
Case "other" 'if it's other do the code below
ComboBoxModel.List = Array("some car", "some other car") 'as above
load _ the array
End Select
ComboBoxModel.ListIndex = 0 'set the second combobox to the first
value _
which would be 0 this will remove the previous array from showing in
the list
End Sub

hope this is of some help

S





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Populate one combo box based on the selection of another combo

Suppose brands and models in columns B & C starting in Row 2 like
this:
Ford Focus
Ford Mustang
Chevy Impala
Chevy Malibu

and cell E1 is DropDown1's cell link. Assign this macro to DropDown1.

Sub DropDown1_Change()
Dim iRow As Integer
Dim strBrand As String
Dim strLoc1 As String

'get selection using DropDown1's cell link
strBrand = ActiveSheet.Cells(ActiveSheet.Range("E1") + 1, 1)
iRow = 2
Do
If ActiveSheet.Cells(iRow, 2) = strBrand And iCt = 0 Then
strLoc = ActiveSheet.Cells(iRow, 3).Loc
iCt = 1
End If
If ActiveSheet.Cells(iRow, 2) < strBrand And iCt = 1 Then
strLoc = strLoc & ":" & ActiveSheet.Cells(iRow - 1, 3).Loc
iCt = 2
End If
iRow = iRow + 1
Loop Until iCt = 2
ActiveSheet.Shapes("Drop Down 2").Select
With Selection
.ListFillRange = strLoc
.LinkedCell = ""
.DropDownLines = 8
.Display3DShading = False
End With
ActiveSheet.Range("E1").Select 'unselects DropDown2
End Sub


Hth,
Merjet


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Populate one combo box based on the selection of another combo

Oops.

"3).Loc" s/b "3).Address" in 2 places

Merjet


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Populate one combo box based on the selection of another combo

I am getting an overflow error message at
iRow = iRow + 1

can I send you the file?

"merjet" wrote:

Oops.

"3).Loc" s/b "3).Address" in 2 places

Merjet



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Populate one combo box based on the selection of another combo

Try:

dim iRow as long

(Instead of integer)

Alex wrote:

I am getting an overflow error message at
iRow = iRow + 1

can I send you the file?

"merjet" wrote:

Oops.

"3).Loc" s/b "3).Address" in 2 places

Merjet




--

Dave Peterson
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
Conditional Formating Based on Selection in a Combo Box adrian007uk Excel Discussion (Misc queries) 4 December 11th 09 08:54 AM
In Excel I need to set up a combo box based on another combo box. donna_ge Excel Discussion (Misc queries) 2 March 29th 06 03:26 PM
Delete from named range based on Combo Box selection shebert Excel Programming 4 August 8th 05 05:18 PM
Combo box values based on other combo box value JCanyoneer Excel Programming 1 April 5th 05 06:41 PM
Filling multiple cells based on 1 combo box selection Serrena Carter Excel Programming 1 August 30th 03 02:14 PM


All times are GMT +1. The time now is 04:42 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"