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

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
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,224,739
Messages
6,180,676
Members
452,993
Latest member
FDARYABEE

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