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
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
The purpose of the code is to "filter out" those abbreviations. The code as iswill not completely delete them
from the sheet.
 
Upvote 0
Sorry my wording is confusing. That is what I ment. When I run the macro those abbreviations aren't filtered out. Is there something that I changed that was incorrect. This is for columb I
 
Upvote 0
Not certain why it doesnt work there. It runs fine here.

Option Explicit Sub DelStates() '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 End Sub [/CODE]
 
Upvote 0
My table goes all the way to column AJ and row 872,678 could that be it? After running it I do a control F in column "I"and I still find all those criteria In the column.
 
Upvote 0
This time I looked up the states manually and change NY to NY and did it to all the cells that contain NY and ran my macro again and it worked. Ideally I would like not to do that
 
Upvote 0
Do you have spaces before the state in the worksheet?
 
Upvote 0
I don't think so. I have another macro that looks like this and it identifies all of them so that's why I'm confused as to why the other macro can't identify them
VBA Code:
.Range("A1").AutoFilter 9, Array("DE", "AK", "MN", "ND", "NE", "OR", "SD", "WA", "WI"), xlFilterValues
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,721
Members
449,093
Latest member
Mnur

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