MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old May 23rd, 2002, 12:15 PM   #1
kurai
New Member
 
Join Date: May 2002
Posts: 19
Default

I would like to create a pulldown menu with options depending on a previously selected item.

I have a list of Items, descrptions, and prices- 3 different prices per item. I want to be able to select the item and in another column, select the prices available for that item. help me please

oh, and what is the maximum number of selections I can put in a pulldown listbox?
kurai is offline   Reply With Quote
Old May 23rd, 2002, 12:23 PM   #2
Brian from Maui
Board Regular
 
Brian from Maui's Avatar
 
Join Date: Feb 2002
Posts: 7,743
Default

kurai,

Not sure if this is what you want

http://www.mrexcel.com/board/viewtop...c=7345&forum=2
Brian from Maui is offline   Reply With Quote
Old May 23rd, 2002, 12:43 PM   #3
Joe Was
MrExcel MVP
 
Joe Was's Avatar
 
Join Date: Feb 2002
Location: Central Florida, USA
Posts: 7,541
Default

You can also do this with a drop-down list, if your values are hard coded in a lookup list. The code below will use one list to lookup values in another list.

The first code is manual the second is automatic.

Sub BuildList()
'By Joe Was
myState = "=" & Worksheets("Sheet1").Range("B1").Value
With Worksheets("Sheet1").Range("D1").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:= _
xlValidAlertStop, Operator:=xlBetween, Formula1:=myState
.IgnoreBlank = True
.InCellDropdown = True
.ShowInput = False
.ShowError = False
End With
End Sub



Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Not Intersect(Target, Range("B1")) Is Nothing Then
myState = "=" & Worksheets("Sheet1").Range("B1").Value
With Worksheets("Sheet1").Range("D1").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:= _
xlValidAlertStop, Operator:=xlBetween, Formula1:=myState
.IgnoreBlank = True
.InCellDropdown = True
.ShowInput = False
.ShowError = False
End With
Else
myState = "=" & Worksheets("Sheet1").Range("B1").Value
With Worksheets("Sheet1").Range("D1").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:= _
xlValidAlertStop, Operator:=xlBetween, Formula1:=myState
.IgnoreBlank = True
.InCellDropdown = True
.ShowInput = False
.ShowError = False
End With
End If
End Sub

To use the code!
Select an item in the dropdown in B1 (Like the: "State")
H column contains the list names for the lists in columns I, J & K, H would be the State list range name for the City list in column I, J & K or more column?
The list selected in B1 will set the dropdown values of D1 (Like the "Cities" in your selected State")

So you have one dropdown in B1 and the other in D1. When you select from the dropdown in B1 your selection loads the range name for the list used for the dropdown in D1. My test is B1 is three States and D1 is the Cities in that selected State. Hope this helps? JSW

P.S. The Private Sub automatically checks for a change in B1,s value and runs the macro to update D1.
Joe Was is offline   Reply With Quote
Old May 23rd, 2002, 02:58 PM   #4
kurai
New Member
 
Join Date: May 2002
Posts: 19
Default

I think I should have stated that I was using data validation not actual pull-downs.
I am sorry if this angers you... I ddnt realize you could do real ones in excel until I read a previous post.
kurai is offline   Reply With Quote
Old May 23rd, 2002, 03:29 PM   #5
kurai
New Member
 
Join Date: May 2002
Posts: 19
Default

I was reading on that post linked to earlier and I came across this

while I have been trying to do this, It dosnt seem to work
why????????


For an example let’s create two drop-downs with B1 being dependent on A1. That is to say what is displayed in A1 will determine what is available in the B1 drop-down list.

Step 1: Create 4 lists on Sheet2
A1=CPU
A2=Memory
A3=HDSZ

B1=P2
B2=P3
B3=P4

C1=128
C2=256
C3=512

D1=Gigbyte
D2=Terabyte

Step 2: Highlight each list and name it.
( naming a list is done with the “Insert” …”name” … toolbar command
2.a. The A:A list can be called anything ..this time lets call it “overview”
2.b. The B:B list Must be called “CPU”
2.c. The C:C list Must be called “Memory”
2.d. The D:D list must be called “HDSZ”

Step3: Go to Sheet1 to make the two drop-downs

Step4: Select sheet1!A1 and select “Data”… “validation” from toolbar commands

Step5: in the validation window the “Allow:” drop down = “lists” and in Source textbx type: “=overview” …. Press OK

Step6: To make the B1 drop down repeat step 4 & 5 ACCEPT in Source textbx type: “=INDIRECT(A1)”

Now Your Done !!!!!!!
kurai is offline   Reply With Quote
Old May 25th, 2002, 12:15 PM   #6
Chris Davison
MrExcel MVP
 
Join Date: Feb 2002
Location: Millbank, London, UK
Posts: 1,790
Default

Kurai,

I believe Brian's link actually does give you all the info you need.

(Joe, I assume yours does too, but I know nothing about VBA, so couldn't comment

Assume you have a list of the 3 items that you sell :

Car (code CAR1)
Train (code TRAIN1)
Plane (code PLANE1)

And as you say, you have 3 different prices for each of them :

Car : $30,000 / $31,000 / $32,000
Train : $1,000,000 / $1,200,000 / $1,300,000
Plane : $450,000 / $500,000 / $999,999

I'm going to *assume* you have a problem with the prices bit of your scenario, not the description bit...... linking the description to the code is an easy VLOOKUP..... if I'm wrong, I apologise, repost and it will easily be solved. It also doesn't affect the prices problem, so I'll continue :

You have 3 different prices for each code. So all you do is list those prices out somewhere WITH THE RESPECTIVE CODES:

CAR1
31,000
32,000
33,000

TRAIN1
1,000,000
1,200,000
1,300,000

PLANE1
450,000
500,000
999,999

now highlight the 3-celled range for CAR1
insert
name
define
names in workbook should be "CAR1"
refers to should be your highlighted range (with $$ signs to anchor it)
add
okay

now highlight the 3-celled range for TRAIN1
insert
name
define
names in workbook should be "TRAIN1"
refers to should be your highlighted range (with $$ signs to anchor it)
add
okay


now highlight the 3-celled range for PLANE1
insert
name
define
names in workbook should be "PLANE1"
refers to should be your highlighted range (with $$ signs to anchor it)
add
okay

you should now have a set of named ranges called "CAR1", "TRAIN1" and "PLANE1"

check this as follows :

edit
goto
reference : =CAR1
okay

it should highlight the 3 cells of prices relating to the sale of your car

repeat for TRAIN1 and PLANE1

now, back to your dropdown lists.....

if your original selection of codes was in, say, C10, wether typed in manually or selected from a dropdown, it should contain one of the following :

CAR1
TRAIN1
PLANE1

Cell D10 will contain the description of that item (ie Car, Train, Plane)

in the next cell, E10, we want to validate it with data based on C10, so in E10 :

data
validation
settings
allow = list
source = =INDIRECT(C10)
okay


__________________
:: Pharma Z - Family drugstore ::
Chris Davison is offline   Reply With Quote
Old May 25th, 2002, 12:37 PM   #7
stevebausch
Board Regular
 
Join Date: May 2002
Posts: 809
Default

If I understand you correctly.....

A drop-down menu (actually, in my case it was a listbox) _Change event will determine what choices will be seen in the adjacent menu.

I suggest keeping all the hidden data in arrays of control, which in my case were Add-ed as Listboxes. These controls are Visible=False; never seen.

You will have a "proxy" control on the form, for each array. By having the proxy, you get to keep Events, since Events are not possible on array of Control. The Events allow you to have cascade of menus, each triggered by any change of the previous menu. Yes, there is a bit of shuffling of data, but I have done it, and it worked wonderfully.
Just be careful of endless _Change loops; you may need to set Application.EventsEnabled = False while doing your magic, then rest to True upon exit.

Have I lost you yet? I hope not. If you need more info, just ask.

Steve
stevebausch is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 01:16 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes