The way you are trying to filter data is wrong. Please, read the documentation:
Range.AutoFilter method (Excel) | Microsoft Docs[
^]
1. I'd avoid of using below code, due to user interaction.
Set mainrng = Application.InputBox("Select the range ", "Advanced_Filter", Selection.Address, Type:=8)
When user hit
Cancel
, your code will return error.
2. Note, that below code:
For Each cell In crange
Avalue = """" & cell & ""","
Next cell
replaces
Avalue
variable content in each iteration.
If you would like to build
Criteria1
, you have to create an array of variant:
Criteria1:=Array("1", "3", "Seattle", "Redmond")
Let's find out what is passed to
Criteria1
input parameter:
Dim Avalue As String
Dim Vvalue As Variant
Avalue = "A,B,10,20"
Vvalue = Array(Avalue)
For i = LBound(Vvalue) To UBound(Vvalue)
Debug.Print Vvalue(i)
Next
Tip: comma separated string instead of an array of variant
Good luck!