ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro: Delete Row Above Last (https://www.excelbanter.com/excel-discussion-misc-queries/200084-macro-delete-row-above-last.html)

D

Macro: Delete Row Above Last
 
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

John Bundy

Macro: Delete Row Above Last
 
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

--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"D" wrote:

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


D

Macro: Delete Row Above Last
 
Thanks! I didn't realize it was that easy.

"John Bundy" wrote:

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

--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"D" wrote:

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


juma

Macro: Delete Row Above Last
 


"D" wrote:

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



All times are GMT +1. The time now is 08:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com