PDA

View Full Version : Array Param Problem with AutoFilter



20rin
12-10-2013, 12:27 AM
Guys what is wrong here???????
F45-F48 is links for checkboxes


Sub Macro4()
'
'Cola
'Pepsi
'AMG
'Other
Dim c1 As String
Dim c2 As String
Dim c3 As String
Dim c4 As String

If Range("F45") = True Then
c1 = "Cola"
Else
c1 = ""
End If
If Range("F46") = True Then
c2 = "Pepsi"
Else
c2 = ""
End If
If Range("F47") = True Then
c3 = "AMG"
Else
c3 = ""
End If
If Range("F48") = True Then
c4 = "Other"
Else
c4 = ""
End If

ActiveSheet.Range("$A$51:$W$828").AutoFilter Field:=9, Criteria1:=Array(c1, c2, c3, c4)

End Sub

SamT
12-12-2013, 04:52 PM
I don't know. What is it doing wrong?


Sub Macro4()
'
'Cola
'Pepsi
'AMG
'Other

Dim c1 As String, c2 As String, c3 As String, c4 As String
'Strings are initialized to ""

If Range("F45") Then c1 = "Cola" 'If X Then is the same as If X = True Then
If Range("F46") Then c2 = "Pepsi" 'One line If... Then works if only one possible result
If Range("F47") Then c3 = "AMG"
If Range("F48") Then c4 = "Other"

ActiveSheet.Range("$A$51:$W$828").AutoFilter Field:=9, Criteria1:=Array(c1, c2, c3, c4)

End Sub

snb
12-13-2013, 04:02 AM
Sub M_snb()
ActiveSheet.Range("$A$51:$W$828").AutoFilter 9, Filter([transpose(if(F45:F48,{"Cola";"Pepsi";"AMG";"other"},"~"))], "~", False)
end sub