PDA

View Full Version : Dynamic listbox, help! Stressed...



MrSteve
11-22-2007, 03:48 AM
So my boss in work has given me a VBA task this week. I've never used VBA before, and as the "technical guy" in the office I always get given these tasks... :banghead:

This is what he wants -

He has an excel template which has data validation on the first two columns. So for example if he selects a country from the listbox in column1, the city listbox in column2 will automatically update with values.

He wants me to add a listbox in column3 which automatically updates based on whatever is selected in column2, and a listbox in column4 which automatically updates based on whatever is selected on column3, etc.

Also, when he goes to a new row, a country listbox should appear in the first column, so he can run through the process again...

Is there any way in VBA to do something similar to data validation, except I can make decisions using IF statements? So if country = USA, cities = this big list.

Is this possible?

The spreadsheet needs to keep the same "feel" as data validation if possible.

I've been trying to figure this out but I'm not getting anywhere. Any help greatly appreciated. Thanks!

Bob Phillips
11-22-2007, 03:50 AM
Use Data validation, http://www.contextures.com/xlDataVal02.html

MrSteve
12-10-2007, 10:32 AM
Thank you.

I have followed the steps as outlined in the tutorial, however there is one small problem.

I have two lists -

Parent Child

When I choose an item in the parent, I should have certain options available in the child.

However if I choose a parent in (for example) row 2, I cannot click on the child list in row 2. My child options are available in row 1.

So everytime I choose a parent the child populates in a previous row.

So -

Row1.................Child2
Row2...Parent2....Child3
Row3...Parent3....Child4
Etc.

Does anyone know what could be causing this?

Attached is the spreadsheet I am using.

Any help greatly appreciated!

Thanks :)

RECrerar
12-11-2007, 04:11 AM
Hi,

It works fine for me. Check the cell you reference for the dependant validation, if it isn'tthe first cell of the independant data then that could be causing the problem

RECrerar
12-11-2007, 04:16 AM
Yeah, just had a look at your sheet, which I probably should have done before the last post. Your referenced in column D all refer to C3, whereas the first cell of data validation in column C is cell C2. I just changed all the referances to C3 to C2 in the formular and it seem to work for me now.

Regards