0

I'm attempting to take a list of names and filter another list based on whether these names appear. To do so, I want to create an array of the names and then take this array to apply an autofilter to the other sheet from a specific column. Here's the code I currently have:

Dim AdvisorEINs As Variant

    AdvisorEINs = Worksheets("Names to Filter").Range("A1:A36").Value
    Worksheets("All Advisors").Range("$A$1:$DZ$2216").AutoFilter Field:=15, Criteria1:=AdvisorEINs.Value, Operator:=xlFilterValues

Currently this is returning Run-time error '424': Object required when attempting to run and debugging is highlighting the filtering line. I've added in a Debug.Print on the AdvisorEINs variable, which outputs the same error message and suggests to me that this is due to variable not picking up data correctly. I'm not certain how to have the array pick up the data any other way - is someone able to advise on this?

2
  • AdvisorEINs is an array of values. Criteria1:=AdvisorEINs.Value treats it like a range. So there is a datatype error in this assignment. It should be Criteria1:=AdvisorEINs. But beyond that, shouldn't Criteria1 be a single value? Is it possible to assign an array to it? Commented Apr 9, 2020 at 10:38
  • @Variatus, yes, provided you specify Operator:=xlFilterValues, as OP's doing Commented Apr 9, 2020 at 10:45

1 Answer 1

2

you have to

  • use AdvisorEINs instead of AdvisorEINs.Value

  • transpose the array , because the Value property of a multicell range returns a 2D array (though with one column only... )

like follows:

Dim AdvisorEINs As Variant

AdvisorEINs = Worksheets("Names to Filter").Range("A1:A36").Value
Worksheets("All Advisors").Range("$A$1:$DZ$2216").AutoFilter Field:=15, Criteria1:=Application.Transpose(AdvisorEINs), Operator:=xlFilterValues
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.