VBA filters using 3 or more criteria

tanyaleblanc

Board Regular
Joined
Mar 16, 2019
Messages
139
I'm trying to filter using 3 criteria but I'm getting an error, here is the code I tried.

With ActiveSheet
.AutoFilterMode = False
With Range("A2:I2")
.AutoFilter
.AutoFilter field:=4, Criteria1:="Text56", Operator:=xlAnd, Criteria2:="Text76", Operator:=xlAnd, Criteria3:="Text80"
End With
End With
 

Some videos you may like

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,862
Office Version
365
Platform
Windows
Try
Code:
With ActiveSheet
   .AutoFilterMode = False
   With .Range("A2:I2")
      .AutoFilter 4, Array("Text56", "Text76", "Text80"), xlFilterValues
   End With
End With
 

tanyaleblanc

Board Regular
Joined
Mar 16, 2019
Messages
139
Works perfect, thank you so much, the purpose of the filter was so that I could delete those lines, but my delete is not working,

Sub Adjust_Report()
Dim lastrow As Long
Dim lRow As Long
Dim Rng As Range
If AutoFilterMode = True And FilterMode = True Then ActiveSheet.ShowAllData
Dim fd As Office.FileDialog
If AutoFilterMode = True And FilterMode = True Then ActiveSheet.ShowAllData
lRow = ActiveSheet.Range("A500").End(xlUp).Row

If Range("f3:f" & lRow).SpecialCells(xlCellTypeVisible).Count > 1 Then
ActiveSheet.Range("a2:j" & lRow).Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End If
 
Last edited:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,862
Office Version
365
Platform
Windows
How about
Code:
Sub Adjust_Report()
With ActiveSheet
   .AutoFilterMode = False
   With .Range("A2:I2")
      .AutoFilter 4, Array("Text56", "Text76", "Text80"), xlFilterValues
   End With
   .AutoFilter.Range.Offset(1).EntireRow.Delete
   .AutoFilterMode = False
End With
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,102,711
Messages
5,488,450
Members
407,638
Latest member
brandynl

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top