VBA: Deleting Visible rows using Auto Filter; Excluding Header

Offroadracer_814

New Member
Joined
Aug 7, 2015
Messages
24
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 am trying to delete all rows that do not have an "****" in the column.
Excel 2024-02-12 100957.jpg

I have more data than that in the column. I just removed all the duplicates for a smaller picture sample.

I have two columns I will use this VBA code for.

Thanks

Kevin
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
This macro will remove all rows that are visible. You will need to filter and show what you want deleted.

VBA Code:
'Put your cursor in the column where you want to delete all visible rows
Sub DeleteVisRows()
    Dim Rng As Range
    Dim Sht As Worksheet
    Dim Cel As Range
    Dim CLM As Long
    
    Set Sht = ActiveSheet
    Set Cel = Selection.Resize(1, 1)
    CLM = Cel.Column
    
    With Sht
      If .Cells(.Cells.Rows.Count, CLM).End(xlUp).Row > 2 Then  'Make sure there is something in this column
          'Row 2 to last non-blank row
        Set Rng = Range(.Cells(2, CLM), .Cells(.Cells.Rows.Count, CLM).End(xlUp))
        Set Rng = Rng.SpecialCells(xlCellTypeVisible).EntireRow
        Rng.Delete
      End If
    End With
      
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

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