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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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