autofilter

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,132
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I am trying to exclude the data but i am facing a road block on Field:=5, rest of the Field is all perfect, on Field:=5 it will exclude the data form the list M3:M7, but no luck.

any way out.


VBA Code:
Sub ExcludeDailyRawData()
    Dim ws As Worksheet
    Dim reportSheet As Worksheet
    Dim exclusionRange As Range
    Dim exclusionValues As Variant
    Dim cell As Range
    Dim criteriaArray() As String
    Dim i As Integer

    ' Set the sheets
    Set ws = ThisWorkbook.Sheets("Daily-RawData")
    Set reportSheet = ThisWorkbook.Sheets("Report")

    ' Clear any existing filters
    If ws.AutoFilterMode Then ws.AutoFilterMode = False

    ' Retrieve exclusion values from Report sheet, range M3:M7
    Set exclusionRange = reportSheet.Range("M3:M7")
    exclusionValues = exclusionRange.Value

    ' Initialize the criteria array
    ReDim criteriaArray(1 To UBound(exclusionValues, 1))

    ' Populate the criteria array
    i = 1
    For Each cell In exclusionRange
        criteriaArray(i) = cell.Value
        i = i + 1
    Next cell

    ' Apply autofilter to column F
    ws.Range("A1").AutoFilter Field:=6, Criteria1:="<>" & "Day"

    ' Apply autofilter to column G
    ws.Range("A1").AutoFilter Field:=7, Criteria1:="<>" & "All Fixed", Operator:=xlAnd, Criteria2:="<>" & "Fiber"

    ' Apply autofilter to column D
    ws.Range("A1").AutoFilter Field:=4, Criteria1:="<>" & "administrative_area_level_1", Operator:=xlAnd, Criteria2:="<>" & "country"

    ' Apply autofilter to column E to exclude specific values from the criteria array
    ws.Range("A1").AutoFilter Field:=5, Criteria1:="<>" & criteriaArray, Operator:=xlFilterValues
   
       MsgBox "Filters have been applied to the 'Daily-RawData' sheet.", vbInformation
End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
You can't use more than two <> criteria on one column.
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,181
Members
452,615
Latest member
bogeys2birdies

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