Macro help

Alvaroro84

Board Regular
Joined
May 13, 2022
Messages
65
Office Version
  1. 2016
Platform
  1. Windows
Im using this code I found here to get rid of these criteria AZ,ME,CA,NY. in column "I" I however cant get it to work. can any one provide me with some assistance
VBA Code:
   'apply a filter, row 1 contains my titles
    Range("A1:L1").Select
    Selection.AutoFilter
 
    Dim filterCriteria() As String
    Dim count As Long, secondArray As Variant
    Dim L As Long, c As String, k As String, rowNumb As Long
   
    secondArray = Array("AZ", " ME", " CA", " NY")
   
    c = 0
    k = 0
    count = 0
    rowNumb = ActiveSheet.Range(ActiveSheet.Range("I2"), ActiveSheet.Range("I1").End(xlDown)).Rows.count
   
    For L = 1 To rowNumb
        c = ActiveSheet.Range("I1").Offset(L)
        If c <> k Then
            'check the current activity type against the array of types we don’t want. If it isn’t in the array we add it to an array that will be used as the filter criteria
            If UBound(Filter(secondArray, c)) = -1 Then
                ReDim Preserve filterCriteria(0 To count)
                filterCriteria(count) = c
                count = count + 1
            End If
 
            k = c
        End If
    Next
   
    With ActiveSheet
        .Range(.Range("A1"), .Range("A1").End(xlDown).Offset(0, 11)).AutoFilter Field:=9, Criteria1:=filterCriteria, Operator:=xlFilterValues
    End With
 
In that case you need to get rid of the spaces in this array
VBA Code:
secondArray = Array("AZ", " ME", " CA", " NY")
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
I initially thought the same thing and that's what I did and it still having the same issue
 
Upvote 0
Are you able to post your workbook for review ? You'll need to use a CLOUD website like DropBox or similar, then provide the link here.
 
Upvote 0
I found a way around it. since my regular filter can find it i do a find and replace
 
Upvote 0

Forum statistics

Threads
1,215,566
Messages
6,125,589
Members
449,237
Latest member
Chase S

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