Dynamic dependent drop down list using an array formula

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
14,151
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I have successfully created a dynamic dependent drop down list. I have used this code to insert the drop down into a range in "Sheet1".
VBA Code:
With desWS.Range("F2:F" & lRow).Validation
        .Delete
        .Add Type:=xlValidateList, Formula1:="=Categories"
    End With
"Categories" refers to a named range: =Type[#Headers] which are the headers in a table in sheet "Lists" - A1:B1 which will be the items in the drop down in F2 of "Sheet1".
The code works properly. However, the following code generates the error "Application defined or object defined error":
VBA Code:
With desWS.Range("G2").Validation
        .Delete
        .Add Type:=xlValidateList, Formula1:="=CatList"
    End With
"CatList" refers to a named range: =OFFSET(Lists!$A$1, 1, MATCH($F$2, Lists!$A$1:$B$1,0)-1, COUNTA(OFFSET(Lists!$A$1, 1, MATCH($F$2, Lists!$A$1:$B$1,0)-1, 20, 1)),1)
This formula should create the items in G2 of "Sheet1"from column A or B in "Lists" depending on the selection in F2 of "Sheet1". It allows the drop down in G2 to be dynamic to include any changes in column A or B in "Lists". I believe that this is an array formula and that is why it is generating the error. Would anyone have any suggestions on how to solve this problem?
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Additionally, I entered this formula manually in G2 and it worked properly:
Excel Formula:
=OFFSET(Lists!$A$1, 1, MATCH($F2, Lists!$A$1:$B$1,0)-1, COUNTA(OFFSET(Lists!$A$1, 1, MATCH($F2, Lists!$A$1:$B$1,0)-1, 20, 1)),1)
Using this macro, it generated the error:
VBA Code:
Sub Test()
    With Range("G2").Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:= _
            "=OFFSET(Lists!$A$1, 1, MATCH($F2, Lists!$A$1:$B$1,0)-1, COUNTA(OFFSET(Lists!$A$1, 1, MATCH($F2, Lists!$A$1:$B$1,0)-1, 20, 1)),1)"
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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