ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Delete 3 end row (https://www.excelbanter.com/excel-worksheet-functions/261213-delete-3-end-row.html)

climate

Delete 3 end row
 
Hi
I want to delete three end row of any sheet. any sheet has different row
number.
Thank's for any help.

your's

Mike H

Delete 3 end row
 
Hi,

This will clear the last 3 rows of the active sheet. Note I the on error
line is to cope when there are less than 3 rows on the sheet

Sub del_Last_3()
Dim LastRow As Long
On Error Resume Next
LastRow = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlRows).Row
ActiveSheet.Rows(LastRow - 2 & ":" & LastRow).ClearContents
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"climate" wrote:

Hi
I want to delete three end row of any sheet. any sheet has different row
number.
Thank's for any help.

your's


Mike H

Delete 3 end row
 
another way

ActiveSheet.Rows(LastRow - 2).Resize(3).ClearContents
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Mike H" wrote:

Hi,

This will clear the last 3 rows of the active sheet. Note I the on error
line is to cope when there are less than 3 rows on the sheet

Sub del_Last_3()
Dim LastRow As Long
On Error Resume Next
LastRow = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlRows).Row
ActiveSheet.Rows(LastRow - 2 & ":" & LastRow).ClearContents
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"climate" wrote:

Hi
I want to delete three end row of any sheet. any sheet has different row
number.
Thank's for any help.

your's


climate

Delete 3 end row
 
Hello Mike
Thank you very much.
Ok
Best regards

"Mike H" wrote:

Hi,

This will clear the last 3 rows of the active sheet. Note I the on error
line is to cope when there are less than 3 rows on the sheet

Sub del_Last_3()
Dim LastRow As Long
On Error Resume Next
LastRow = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlRows).Row
ActiveSheet.Rows(LastRow - 2 & ":" & LastRow).ClearContents
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"climate" wrote:

Hi
I want to delete three end row of any sheet. any sheet has different row
number.
Thank's for any help.

your's


Mike H

Delete 3 end row
 
Your welcome

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"climate" wrote:

Hello Mike
Thank you very much.
Ok
Best regards

"Mike H" wrote:

Hi,

This will clear the last 3 rows of the active sheet. Note I the on error
line is to cope when there are less than 3 rows on the sheet

Sub del_Last_3()
Dim LastRow As Long
On Error Resume Next
LastRow = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlRows).Row
ActiveSheet.Rows(LastRow - 2 & ":" & LastRow).ClearContents
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"climate" wrote:

Hi
I want to delete three end row of any sheet. any sheet has different row
number.
Thank's for any help.

your's


Jacob Skaria

Delete 3 end row
 
If you are looking for a macro to delete the last 3 rows try the below

Sub MyMacro()
Dim lngLastRow As Long

lngLastRow = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, SearchOrder:=xlRows).Row
Rows(lngLastRow).Offset(-2).Resize(3).Select
End Sub

--
Jacob (MVP - Excel)


"climate" wrote:

Hi
I want to delete three end row of any sheet. any sheet has different row
number.
Thank's for any help.

your's


Jacob Skaria

Delete 3 end row
 
Oops...Missed to delete..

Sub MyMacro()
Dim lngLastRow As Long

lngLastRow = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, SearchOrder:=xlRows).Row
Rows(lngLastRow).Offset(-2).Resize(3).Delete
End Sub

--
Jacob (MVP - Excel)


"climate" wrote:

Hi
I want to delete three end row of any sheet. any sheet has different row
number.
Thank's for any help.

your's



All times are GMT +1. The time now is 01:27 PM.

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