VBA to Remove Rows

chaddres

Board Regular
Joined
Jun 14, 2014
Messages
143
Office Version
  1. 365
Platform
  1. Windows
I have a spreadsheet with data and I would like a macro to delete all rows of data on the spreadsheet. The number of rows can vary, but column A always has data, so I know we can count the rows in that column to know how many lines of data to delete. I do not want to delete row 1 (header row).

Thank you in advance.
 

Attachments

  • Screenshot 2022-10-07 075108.png
    Screenshot 2022-10-07 075108.png
    93.2 KB · Views: 8

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
One way:
VBA Code:
Sub MyDeleteRows()
    Dim lr As Long
    lr = Cells(Rows.Count, "A").End(xlUp).Row
    If lr > 1 Then Rows("2:" & lr).Delete
End Sub
 
Upvote 0
Solution
That image shows a filtered result. Are you wanting to delete all rows or just visible filtered rows?
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,269
Members
449,075
Latest member
staticfluids

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