AutoFilter now working

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,132
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I have this code and its working all perfect not sure why it is not filtering the data, can this be fixed.

VBA Code:
Sub PPT3()


Dim Fpath As String
Dim oFolder As Object, oFile As Object, i As Integer
    Dim yDir As String

Fpath = ActiveWorkbook.Path & "\" & "Gaming Region RawFile"

Workbooks.Open Filename:=Fpath & "\" & "Gaming_per-region-kpis.csv"

Range("o1").Formula = "=MAX(A2:A50000)"
    
    
  Dim lRow3 As Long
  Dim lColumn3 As Long
  

  lRow3 = Range("A1").End(xlDown).Row
  lColumn3 = Range("A1").End(xlToRight).Column
        
  Cells(lRow3, lColumn3).Select
  Range("a1").Select
  Selection.AutoFilter
    Range("A1").Select
    
    On Error Resume Next
    ActiveSheet.Range("A1" & lRow3).AutoFilter Field:=1, Operator:= _
        xlFilterValues, Criteria2:="<>" & Array(1, Range("o1").Value) ' Here its not filter the data.
        'xlFilterValues , Criteria2:="<>" & Array(1, Range("o1").Value)
       
    Range("A1:G" & lRow3).Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    Selection.AutoFilter
    
    [ATTACH type="full"]99395[/ATTACH]
    
    
    
    
    
    
    
    
End Sub
 

Attachments

  • 1695835861575.png
    1695835861575.png
    30.7 KB · Views: 8

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
You have a few typos in your code, mainly on the range you are trying to filter.
Try this:
VBA Code:
Sub PPT3()


Dim Fpath As String
Dim oFolder As Object, oFile As Object, i As Integer
    Dim yDir As String

Fpath = ActiveWorkbook.Path & "\" & "Gaming Region RawFile"

Workbooks.Open Filename:=Fpath & "\" & "Gaming_per-region-kpis.csv"

Range("O1").Formula = "=MAX(A2:A50000)"
    
    
  Dim lRow3 As Long
  Dim lColumn3 As Long
  Dim f As String
  
  lRow3 = Range("A1").End(xlDown).Row
  lColumn3 = Range("A1").End(xlToRight).Column
        
  Range("A1").AutoFilter
    
    On Error Resume Next
    ActiveSheet.Range("A1:G1" & lRow3).AutoFilter Field:=1, Operator:= _
        xlFilterValues, Criteria2:=Array(2, Range("O1").Value)
       
    Range("A1:G" & lRow3).Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    Selection.AutoFilter
   
End Sub
 
Upvote 0
ok,

just want that this code should be not equla too, currently its nor working.

VBA Code:
    ActiveSheet.Range("A1:G1" & lRow3).AutoFilter Field:=1, Operator:= _
        xlFilterValues, Criteria2:="<>" & Array(2, Range("O1").Value)
 
Upvote 0
Try this:
VBA Code:
Sub PPT3()

    Dim Fpath As String
    Dim oFolder As Object, oFile As Object, i As Integer
    Dim yDir As String
    Dim lRow3 As Long
    Dim lColumn3 As Long
    Dim crit As String

    Fpath = ActiveWorkbook.PATH & "\" & "Gaming Region RawFile"

    Workbooks.Open Filename:=Fpath & "\" & "Gaming_per-region-kpis.csv"

'   Set criteria
    Range("O1").Formula = "=MAX(A2:A50000)"
    crit = "<>" & Format(Range("O1").Value, "mm/dd/yyyy")
    
    lRow3 = Range("A1").End(xlDown).Row
    lColumn3 = Range("A1").End(xlToRight).Column
        
    Range("A1").AutoFilter
    
    On Error Resume Next
    ActiveSheet.Range("A1:G1" & lRow3).AutoFilter Field:=1, Criteria1:= _
        crit, Operator:=xlAnd
       
    Range("A1:G" & lRow3).Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    Selection.AutoFilter
   
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

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