Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default find and delete rows macro

Hello,

I have created a macro to re-format a report i receive in excel. I'm having
a problem adding the following instruction.

I need to use the macro to find and select the last five rows, then delete
those rows. This is a problem because the report length varies each day when
i receive the report.

Even if there is one to find and select just the last row. I can repeat 5
times.

Clay
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,101
Default find and delete rows macro

This might work for you
Sub deleterows()
Dim rng As Range
Dim i As Long

Set rng = ActiveSheet.Range(Cells(1, "A"), _
Cells(Rows.Count, "A").End(xlUp))

With rng
For i = .Rows.Count To .Rows.Count - 4 Step -1
.Cells(i).EntireRow.Delete
Next i
End With
End Sub

"clayton ledford" wrote:

Hello,

I have created a macro to re-format a report i receive in excel. I'm having
a problem adding the following instruction.

I need to use the macro to find and select the last five rows, then delete
those rows. This is a problem because the report length varies each day when
i receive the report.

Even if there is one to find and select just the last row. I can repeat 5
times.

Clay

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default find and delete rows macro

Maybe

lastrow = UsedRange.Rows.Count
Rows(lastrow).Offset(-4).EntireRow.Resize(5,
ActiveSheet.Columns.Count).ClearContents

Mike

"clayton ledford" wrote:

Hello,

I have created a macro to re-format a report i receive in excel. I'm having
a problem adding the following instruction.

I need to use the macro to find and select the last five rows, then delete
those rows. This is a problem because the report length varies each day when
i receive the report.

Even if there is one to find and select just the last row. I can repeat 5
times.

Clay

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,124
Default find and delete rows macro

Try this. Change column to suit. To delete simply change
..select
to
..delete

Sub selectlastfive()
mc = 6 ' "f"
'Cells(Rows.Count, mc).End(xlUp).Resize(-5).Select
'since resize doesn't work for negative

Cells(Rows.Count, mc).End(xlUp).Offset(-4).Resize(5).Select
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"clayton ledford" wrote in
message ...
Hello,

I have created a macro to re-format a report i receive in excel. I'm
having
a problem adding the following instruction.

I need to use the macro to find and select the last five rows, then delete
those rows. This is a problem because the report length varies each day
when
i receive the report.

Even if there is one to find and select just the last row. I can repeat 5
times.

Clay


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default find and delete rows macro

This one worked perfectly. Genius. Thanks guys.

"Mike" wrote:

This might work for you
Sub deleterows()
Dim rng As Range
Dim i As Long

Set rng = ActiveSheet.Range(Cells(1, "A"), _
Cells(Rows.Count, "A").End(xlUp))

With rng
For i = .Rows.Count To .Rows.Count - 4 Step -1
.Cells(i).EntireRow.Delete
Next i
End With
End Sub

"clayton ledford" wrote:

Hello,

I have created a macro to re-format a report i receive in excel. I'm having
a problem adding the following instruction.

I need to use the macro to find and select the last five rows, then delete
those rows. This is a problem because the report length varies each day when
i receive the report.

Even if there is one to find and select just the last row. I can repeat 5
times.

Clay

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
find & delete rows based on text deb Excel Discussion (Misc queries) 4 September 17th 08 01:02 AM
find text and delete rows. John Excel Discussion (Misc queries) 5 December 12th 07 04:25 AM
Find and delete all other rows Murray Excel Discussion (Misc queries) 1 August 7th 07 02:54 AM
Find & delete rows with ID's from another sheet. plys Excel Discussion (Misc queries) 1 December 21st 06 04:21 PM
Macro to find and delete rows! Heather O'Malley Excel Discussion (Misc queries) 2 April 12th 06 01:53 PM


All times are GMT +1. The time now is 02:54 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"