Macro: Delete Row Above Last

  • Thread starter Thread starter D
  • Start date Start date
D

D

Hi,
I am trying to create a macro to delete the line above my totals line (which
is the last line in the sheet).

I am using the following macro to delete a line but am not sure how to
modify it. Any advice is appreciated.

------
Sub DeleteLine()
Dim last_row As Long

ActiveSheet.UsedRange
last_row = Cells.SpecialCells(xlLastCell).Row

Range("A" & last_row).Select
Selection.EntireRow.Delete
End Sub
 
Last_Row contains the last row number and you want to delete the one before
it, so change your select like this
Range("A" & last_row-1).Select
or you could change it when you set the value like this
last_row = Cells.SpecialCells(xlLastCell).Row-1
 
Thanks! I didn't realize it was that easy.

John Bundy said:
Last_Row contains the last row number and you want to delete the one before
it, so change your select like this
Range("A" & last_row-1).Select
or you could change it when you set the value like this
last_row = Cells.SpecialCells(xlLastCell).Row-1
 
D said:
Hi,
I am trying to create a macro to delete the line above my totals line (which
is the last line in the sheet).

I am using the following macro to delete a line but am not sure how to
modify it. Any advice is appreciated.

------
Sub DeleteLine()
Dim last_row As Long

ActiveSheet.UsedRange
last_row = Cells.SpecialCells(xlLastCell).Row

Range("A" & last_row).Select
Selection.EntireRow.Delete
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top