VBA delete last row help

Dan88

Active Member
Joined
Feb 14, 2008
Messages
275
Office Version
  1. 365
Platform
  1. Windows
Hello everyone.

I am trying to piece meal my VBA where I need it to select all sheets in the workbook and delete the last row in each sheet.

Each sheet has the same headers but varies in row so as long as it is the last row being deleted it will work.

Any pointers would be greatly appreciated.

Thanks


Sub deletelastrow()

Dim ws As Worksheet
Dim lastRow As Integer

For Each ws In Worksheets
lastRow = Worksheets.Range("A65536").End(xlUp).Row
Worksheets.Rows(lastRow & ":" & lastRow).Delete shift:=xlUp

Next ws

End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
try

Code:
Dim ws As Worksheet
Dim lastRow As Integer

For Each ws In Worksheets
lastRow = ws.Cells(Rows.Count, "A").End(xlUp).Row
ws.Rows(lastRow & ":" & lastRow).Delete shift:=xlUp

Next ws

hth,
Ross
 
Upvote 0
Or
Code:
For Each ws In Worksheets
    ws.Range("A" & Rows.Count).End(xlUp).EntireRow.Delete
Next ws
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,748
Messages
6,174,264
Members
452,553
Latest member
red83

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