VBA Filtering

chaddres

Board Regular
Joined
Jun 14, 2014
Messages
150
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: 11

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,224,856
Messages
6,181,427
Members
453,040
Latest member
Santero

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