PC Review


Reply
Thread Tools Rate Thread

Deleting rows following the max point

 
 
Lucile
Guest
Posts: n/a
 
      19th Dec 2008
Hi all,
I have set of data that increase to reach a maximum and decrease after that.
I need to find the maximum and delete all the data after this maximum.
I can not find how to delete the entire row after my max point....

The begining of my code:

Sub remove_decrease()
'Remove decrease portion portion
Dim top
top = Application.Match(Application.max(Columns(1)), Columns(1), 0)
'Give the position of the maximum force = top
top = top + 1
'.... need to remove all the next rows...
End Sub


Thanks!
 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      19th Dec 2008
Hi,

Try this

Sub remove_decrease()
Dim RowNo As Long, lastrow As Long
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
TheMax = WorksheetFunction.Max(Columns(1))
TheRow = Columns(1).Find(What:=TheMax, After:=Cells(1, 1)).Row
Range("A" & TheRow + 1 & ":A" & lastrow).ClearContents
End Sub

Mike

"Lucile" wrote:

> Hi all,
> I have set of data that increase to reach a maximum and decrease after that.
> I need to find the maximum and delete all the data after this maximum.
> I can not find how to delete the entire row after my max point....
>
> The begining of my code:
>
> Sub remove_decrease()
> 'Remove decrease portion portion
> Dim top
> top = Application.Match(Application.max(Columns(1)), Columns(1), 0)
> 'Give the position of the maximum force = top
> top = top + 1
> '.... need to remove all the next rows...
> End Sub
>
>
> Thanks!

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      19th Dec 2008
Ah,

You wanted to delete the entire row not just clear then contents. Try this
instead

Sub remove_decrease()
Dim RowNo As Long, lastrow As Long
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
TheMax = WorksheetFunction.Max(Columns(1))
TheRow = Columns(1).Find(What:=TheMax, After:=Cells(1, 1)).Row
Range("A" & TheRow + 1 & ":A" & lastrow).EntireRow.Delete
End Sub

Mike

"Mike H" wrote:

> Hi,
>
> Try this
>
> Sub remove_decrease()
> Dim RowNo As Long, lastrow As Long
> lastrow = Cells(Rows.Count, "A").End(xlUp).Row
> TheMax = WorksheetFunction.Max(Columns(1))
> TheRow = Columns(1).Find(What:=TheMax, After:=Cells(1, 1)).Row
> Range("A" & TheRow + 1 & ":A" & lastrow).ClearContents
> End Sub
>
> Mike
>
> "Lucile" wrote:
>
> > Hi all,
> > I have set of data that increase to reach a maximum and decrease after that.
> > I need to find the maximum and delete all the data after this maximum.
> > I can not find how to delete the entire row after my max point....
> >
> > The begining of my code:
> >
> > Sub remove_decrease()
> > 'Remove decrease portion portion
> > Dim top
> > top = Application.Match(Application.max(Columns(1)), Columns(1), 0)
> > 'Give the position of the maximum force = top
> > top = top + 1
> > '.... need to remove all the next rows...
> > End Sub
> >
> >
> > Thanks!

 
Reply With Quote
 
Lucile
Guest
Posts: n/a
 
      19th Dec 2008
Exellent!! Thank you very much!

"Mike H" wrote:

> Hi,
>
> Try this
>
> Sub remove_decrease()
> Dim RowNo As Long, lastrow As Long
> lastrow = Cells(Rows.Count, "A").End(xlUp).Row
> TheMax = WorksheetFunction.Max(Columns(1))
> TheRow = Columns(1).Find(What:=TheMax, After:=Cells(1, 1)).Row
> Range("A" & TheRow + 1 & ":A" & lastrow).ClearContents
> End Sub
>
> Mike
>
> "Lucile" wrote:
>
> > Hi all,
> > I have set of data that increase to reach a maximum and decrease after that.
> > I need to find the maximum and delete all the data after this maximum.
> > I can not find how to delete the entire row after my max point....
> >
> > The begining of my code:
> >
> > Sub remove_decrease()
> > 'Remove decrease portion portion
> > Dim top
> > top = Application.Match(Application.max(Columns(1)), Columns(1), 0)
> > 'Give the position of the maximum force = top
> > top = top + 1
> > '.... need to remove all the next rows...
> > End Sub
> >
> >
> > Thanks!

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      19th Dec 2008
Glad I could help

"Lucile" wrote:

> Exellent!! Thank you very much!
>
> "Mike H" wrote:
>
> > Hi,
> >
> > Try this
> >
> > Sub remove_decrease()
> > Dim RowNo As Long, lastrow As Long
> > lastrow = Cells(Rows.Count, "A").End(xlUp).Row
> > TheMax = WorksheetFunction.Max(Columns(1))
> > TheRow = Columns(1).Find(What:=TheMax, After:=Cells(1, 1)).Row
> > Range("A" & TheRow + 1 & ":A" & lastrow).ClearContents
> > End Sub
> >
> > Mike
> >
> > "Lucile" wrote:
> >
> > > Hi all,
> > > I have set of data that increase to reach a maximum and decrease after that.
> > > I need to find the maximum and delete all the data after this maximum.
> > > I can not find how to delete the entire row after my max point....
> > >
> > > The begining of my code:
> > >
> > > Sub remove_decrease()
> > > 'Remove decrease portion portion
> > > Dim top
> > > top = Application.Match(Application.max(Columns(1)), Columns(1), 0)
> > > 'Give the position of the maximum force = top
> > > top = top + 1
> > > '.... need to remove all the next rows...
> > > End Sub
> > >
> > >
> > > Thanks!

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro for deleting rows and serialising the remaing rows Srinivasulu Bhattaram Microsoft Excel Worksheet Functions 1 12th Nov 2008 01:39 PM
Macro for deleting rows and serialising the remaing rows Srinivasulu Bhattaram Microsoft Excel Discussion 1 12th Nov 2008 01:32 PM
Excel VBA count rows from certain point and insert rows Valerie Microsoft Outlook VBA Programming 2 27th Nov 2007 02:27 PM
Deleting rows to a defined point =?Utf-8?B?VGltIEdyZWVu?= Microsoft Excel Programming 2 21st Mar 2006 03:55 PM
Excel 2000 VBA Deleting Rows when certain text in rows exists scain2004 Microsoft Excel New Users 1 15th Mar 2004 02:11 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:28 PM.