VBA delete last row help

Dan88

Active Member
Joined
Feb 14, 2008
Messages
272
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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
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,212,927
Messages
6,110,731
Members
448,294
Latest member
jmjmjmjmjmjm

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