VBA Filtering

chaddres

Board Regular
Joined
Jun 14, 2014
Messages
143
Office Version
  1. 365
Platform
  1. Windows
I am currently filtering for "Salary" in the below pivot table and then deleting the rows that are have the entry. I need to add one additional filter called DeclaredTips and filter it for <> 0 after I filter for Salary. DeclaredTips is in Column X. SO, I want to remove all Salary where DeclaredTips <> 0.

VBA Code:
'Pay Type
    Rows("1:1").Select
    Selection.AutoFilter
    With ActiveWindow
        .SplitColumn = 0
        .SplitRow = 1
    End With
    ActiveWindow.FreezePanes = True
    Range("A1").Select
    Dim LastRowOne As Long
    LastRowOne = Cells(Rows.Count, "A").End(xlUp).Row
    Range("N2").Select
    ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-13],Data!C[-13]:C[26],17,FALSE)"
    Range("N2:N" & Range("B" & Rows.Count).End(xlUp).Row).FillDown
    ActiveSheet.Range("$A$1:$BH$" & LastRowOne).AutoFilter Field:=14, Criteria1:= _
        "Salary"
    With ActiveSheet.AutoFilter.Range
    If .Columns(1).SpecialCells(xlVisible).Count > 1 Then
      .Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete
      If .Parent.FilterMode Then .Parent.ShowAllData
    End If
    End With
    Rows("1:1").Select
    Selection.AutoFilter
    Selection.AutoFilter
    Dim LastRowTwo As Long
    LastRowTwo = Cells(Rows.Count, "A").End(xlUp).Row
    ActiveSheet.Range("$A$1:$BH$" & LastRowTwo).AutoFilter Field:=6, Criteria1:= _
    "0"
    With ActiveSheet.AutoFilter.Range
    If .Columns(1).SpecialCells(xlVisible).Count > 1 Then
      .Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete
      If .Parent.FilterMode Then .Parent.ShowAllData
    End If
    End With
    Selection.AutoFilter
    Selection.AutoFilter
    Range("N2").Select
    ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-13],Data!C[-13]:C[26],15,FALSE)"
    Range("N2:N" & Range("B" & Rows.Count).End(xlUp).Row).FillDown
    Selection.AutoFilter
    Selection.AutoFilter
    Range("N1").Select
    Selection.FormulaR1C1 = "JOBCODE"
 

Attachments

  • Screenshot 2022-09-23 112640.png
    Screenshot 2022-09-23 112640.png
    119.7 KB · Views: 9

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,214,821
Messages
6,121,762
Members
449,048
Latest member
excelknuckles

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