VBA: Deleting Visible rows using Auto Filter; Excluding Header

Offroadracer_814

New Member
Joined
Aug 7, 2015
Messages
23
Am a basic VBA user. I mainly use the record function to create my macros and then update as much as possible. I am creating a report at work that takes the same repetitive steps. So I am wanting to macro as much as I can. But, I do not know how to macro to Delete Visible Row using the Auto Filter. Excluding the header. (I need to keep the header for two pivot tables. Which, can we use a macro to create Pivot tables?)
In column Eight, I need to remove all rows that there is no data in that column. Then in Column 18, I need to remove all rows that has a 1 in that column.

Below is my current VBA/Macro.

Thanks in advance.

Kevin

VBA Code:
Sub B_N_B_2_2()
'
' B_N_B_2_2 Macro
'

'
    ActiveSheet.Name = "Black-N-Blue Report"
    Dim Lrow As Long, Lcol As Long
    Lrow = Range("A" & Rows.Count).End(xlUp).Row
    Lcol = Cells(1, Columns.Count).End(xlToLeft).Column
    Cells.Select
    ActiveWorkbook.Worksheets("Black-N-Blue Report").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Black-N-Blue Report").Sort.SortFields.Add Key:= _
        Range("H2:H" & Lrow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
        :=xlSortNormal
    ActiveWorkbook.Worksheets("Black-N-Blue Report").Sort.SortFields.Add Key:= _
        Range("E2:E" & Lrow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
        :=xlSortNormal
    ActiveWorkbook.Worksheets("Black-N-Blue Report").Sort.SortFields.Add Key:= _
        Range("G2:G" & Lrow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
        :=xlSortNormal
    With ActiveWorkbook.Worksheets("Black-N-Blue Report").Sort
        .SetRange Range("A1:S10000")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$S$1068").AutoFilter Field:=8, Criteria1:="="
    Rows("192:1069").Select
    Selection.Delete Shift:=xlUp
    Cells.Select
    ActiveSheet.ShowAllData
    ActiveSheet.Range("$A$1:$S$191").AutoFilter Field:=18, Criteria1:="1"
    Rows("142:185").Select
    Selection.Delete Shift:=xlUp
    ActiveSheet.ShowAllData
           
End Sub
 
Last edited by a moderator:

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Try:
VBA Code:
Sub B_N_B_2_2()
    On Error Resume Next
    Columns("H").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    Columns("R").Replace "1", "#N/A", xlWhole, , False
    Columns("R").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
    On Error GoTo 0
End Sub
 
Upvote 1
Solution
Try:
VBA Code:
Sub B_N_B_2_2()
    On Error Resume Next
    Columns("H").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    Columns("R").Replace "1", "#N/A", xlWhole, , False
    Columns("R").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
    On Error GoTo 0
End Sub
Thanks for the assistance.

Where in the code would I place this? This is all new to me. Once I learn it. I can use it as reference for other macros.

Thanks again.

Kevin
 
Upvote 0
Try:
VBA Code:
Sub B_N_B_2_2()
    On Error Resume Next
    Columns("H").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    Columns("R").Replace "1", "#N/A", xlWhole, , False
    Columns("R").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
    On Error GoTo 0
End Sub

I figured out where it went. Thanks again!

It worked as I envisioned.
 
Upvote 0
You are very welcome. :)
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,958
Members
449,096
Latest member
Anshu121

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