jengesmeriz
New Member
- Joined
- May 9, 2018
- Messages
- 2
Hi,
I'm trying to create a macro that will filter multiple values using array. However, I'm not sure what is the problem on the code and it wont filter more than two criteria. Im trying to filter column I if it contains "*Extra Air*", "*Extra-Air*", "*ExtraAir*", and if it does then I will tag it as Extra Air Con. The formula works for two criteria, but if I added another one, it wont work. Can anyone help me on this? Below is my sample code.
Sub categorized()
Dim lastRow as long
Dim ws as worksheet
Set ws = Worksheet("Test")
lastRow = ws.Range("I" & Rows.Count).End(xlUp).Row
With ws
.Range("I:I").Autofilter Field:=1, Criteria1:=Array("*Extra Air*", "*Extra-Air*", "*ExtraAir*"), Operator:=xlFilterValues
On error resume next
If lastRow >2 Then
.Range(.Range("C3"),.Range("C" & lastRow)). _
SpecialCells(xlCellTypeVisible).Value = "Extra Air Con"
End if
.AutofilterMode = False
End Sub
I'm trying to create a macro that will filter multiple values using array. However, I'm not sure what is the problem on the code and it wont filter more than two criteria. Im trying to filter column I if it contains "*Extra Air*", "*Extra-Air*", "*ExtraAir*", and if it does then I will tag it as Extra Air Con. The formula works for two criteria, but if I added another one, it wont work. Can anyone help me on this? Below is my sample code.
Sub categorized()
Dim lastRow as long
Dim ws as worksheet
Set ws = Worksheet("Test")
lastRow = ws.Range("I" & Rows.Count).End(xlUp).Row
With ws
.Range("I:I").Autofilter Field:=1, Criteria1:=Array("*Extra Air*", "*Extra-Air*", "*ExtraAir*"), Operator:=xlFilterValues
On error resume next
If lastRow >2 Then
.Range(.Range("C3"),.Range("C" & lastRow)). _
SpecialCells(xlCellTypeVisible).Value = "Extra Air Con"
End if
.AutofilterMode = False
End Sub