Array Defined by Cell Entry

helpexcel

Well-known Member
Joined
Oct 21, 2009
Messages
656
I'm using this code to filter a list on ws2 based on lists on ws1. I have 10 lists each with different variables. I want to be able to put a validation list in a cell on ws2 with the names of each list on ws1. This input would then be used to define "Ary" below. Is this just a matter of using 10 if/else/thens, or is there an easier way to do it?

Thanks!

Ary = Application.Transpose(ws1.Range(("A3"), ws1.Range("A3").End(xlDown)))
With ws2
.Range("A:A").AutoFilter 1, Ary, xlFilterValues
End With
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
I tried the IF/THEN/ELSE Methind and i'm getting an error on the * line saying "AutoFilter method of Range class Failed." Any ideas on how to correct?

If ThisWorkbook.Worksheets("Sheet1").Range("C1") = "Apple" Then
Ary = Application.Transpose(ws1.Range(("A3"), ws1.Range("A3").End(xlDown)))

ElseIf ThisWorkbook.Worksheets("Sheet1").Range("C1") = "Orange" Then
Ary = Application.Transpose(ws1.Range(("B3"), ws1.Range("B3").End(xlDown)))

ElseIf ThisWorkbook.Worksheets("Sheet1").Range("C1") = "Pear" Then
Ary = Application.Transpose(ws1.Range(("C3"), ws1.Range("C3").End(xlDown)))

End If

With Sheets("Sheet2")
* .Range("A:A").AutoFilter 1, Ary, xlFilterValues
End With
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,259
Members
452,626
Latest member
huntinghunter

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