Conditional Dropdown box entries

GMBJames

New Member
Joined
Aug 21, 2002
Messages
22
Hello all,
I am using excel 2000 on a win98se machine.
I have a macro created to launch a form with the code below:

Private Sub UserForm_Initialize()
Dim TitleTxt As String
TitleTxt = "Fulltime"
With Me.ComboBox1
.AddItem "Fulltime"
.AddItem "Partime"
.Text = TitleTxt
End With
End Sub

Here's my question:
I'd like to add another dropdown box on the same form however, depending upon which entry above is selected, ("Fulltime" or "Partime") the contents of the second box would change. For example, if the user select "Fulltime", I'd like the choices of the second box to be "Monday" and "Friday". And if they select "Partime" from the first box, I'd like the choices of the second box to be "Saturday" and "Sunday".

Any help will be greatly appreciated.
Thanks,
Jamie
 

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.
Juan,
thanks for the reply. The information you've posted works however, is there any way to do this in VBA instead of having the user click on a cell in the spreadsheet? I'd really like for the user to be able to do this from a userform.
Thank you for your time,
Jamie
 
Upvote 0
On 2002-09-14 11:07, GMBJames wrote:
Juan,
thanks for the reply. The information you've posted works however, is there any way to do this in VBA instead of having the user click on a cell in the spreadsheet? I'd really like for the user to be able to do this from a userform.
Thank you for your time,
Jamie

Hi Jamie,

You add the second box to the form in design mode and change your initilalize code to:

Private Sub UserForm_Initialize()
Dim TitleTxt As String
TitleTxt = "Fulltime"
With Me.ComboBox1
.AddItem "Fulltime"
.AddItem "Partime"
.Text = TitleTxt
End With
With ComboBox2
.Clear
.AddItem "Monday"
.AddItem "Friday"
End With

End Sub

and add following code:

Private Sub ComboBox1_Change()
Dim TitleTxt As String
Select Case ComboBox1.ListIndex
Case 0:
With ComboBox2
.Clear
.AddItem "Monday"
.AddItem "Friday"
End With
Case 1:
With ComboBox2
.Clear
.AddItem "Saturday"
.AddItem "Sunday"
End With
Case Else
End Select
End Sub

Hope this is what you want :)
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,208
Members
448,554
Latest member
Gleisner2

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