Nested / Conditional / Dependent drop down in VBA

vivekp

New Member
Joined
Apr 15, 2014
Messages
1
I've been racking my brain trying to figure how to solve this for the last week and a half. The core of my formula works in Excel but not in VBA.

The basic concept I'm trying to accomplish is to make one drop-down dependent on the result of another drop-down.

The first drop-down has a list of parent categories. I wrote a macro that cycles through all of the parent categories and creates a named range for each parent category that contains the relevant subsidiary categories choices for the second drop-down. I tested this in Excel and it works beautifully with indirect and offset and match but when I tried it in VBA it errors out. I've tried a lot of different iterations but let me show you the latest:

Here is the data from which the drop downs are created (sheet name is "Colors"). The range names column is something that my previous macro already created. The upgrade column contains the drop-down choices for the first drop-down. The columns with color as their title contain the subsidiary drop-down choices. The range name refers to these subsidiary choices.

ABCDEFG
Range namesUpgradeColor 1Color 2Color 3Color 4Color 5
_
_StandardCarpetStandard CarpetBrownGreenBlue
_1stUpgradeCarpet1st Upgrade CarpetBlackBrownGreenBlue
_2ndUpgradeCarpet2nd Upgrade CarpetRed
_3rdUpgradeCarpet3rd Upgrade CarpetBrownGreenBlue
_4thUpgradeCarpet4th Upgrade CarpetYellowPurple

<tbody>
</tbody>


Here is the code that I'm using:

ActiveCell.Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertInformation, Operator:= xlBetween, Formula1:="=if(isblank(activecell.offset(0,-1))," & Chr(34) & "N/A" & Chr(34) & ",indirect(offset(colors!a1,match(activecell.offset(0,-1),colors!b:b,0)-1,0,1,1) ) )"

I have tried a whole variety of different combinations. I tried hard coding the reference cell, adjusting the error-checking in the beginning of the if statement, changing the alert style. I have not tried many different formulas in terms of indirect, match, offset but I did try that exact text directly in Excel (with of course the appropriate adjustments for non-VBA) and it worked perfectly.

Seeing as how I've spent about 15 to 20 hours on this one line of code, any help would be unbelievably appreciated.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,215,343
Messages
6,124,394
Members
449,155
Latest member
ravioli44

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