PC Review


Reply
Thread Tools Rate Thread

Delete cells below a certain rank

 
 
Dallman Ross
Guest
Posts: n/a
 
      2nd Oct 2008
I have two columns, G and I, that I used together. G has a number
in it and I has a date/time stamp. Here is an example:

18.32 10/2/08 14:49
19.99 9/26/08 21:36


Not all the cells are filled in. Many are blank. There
are about 200 or fewer rows in the sheet.

I want to have a macro delete entries from both columns
based on ranked aging of the date/time stamp. Leave the
X newest entries (such as 3 or 5 or 10) and delete others.

I started to code this but ran into trouble. Here
is what I have. Can someone help me get this to work?
It would be much appreciated.

'--------------
Dim cell As Range
Dim testI As Range

' Some unrelated stuff deleted ...

For Each cell In Range("G2:G500")
If cell <> "" Then
Set testI = cell.Offset(0, 2)
Debug.Print testI
If Not Application.WorksheetFunction.Rank(testI, _
Range("G2:G500")) < 6 Then
Range(cell, testI).Clear
End If
End If
Next 'cell
'--------------

Thanks for any help, guys.

=dman=
 
Reply With Quote
 
 
 
 
Barb Reinhardt
Guest
Posts: n/a
 
      3rd Oct 2008
I'd guess you'd want to calculate the rank against the same cell, but you
aren't doing that. You change it every iteration through the For/Next loop.
Is that what you want to do?
--
HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



"Dallman Ross" wrote:

> I have two columns, G and I, that I used together. G has a number
> in it and I has a date/time stamp. Here is an example:
>
> 18.32 10/2/08 14:49
> 19.99 9/26/08 21:36
>
>
> Not all the cells are filled in. Many are blank. There
> are about 200 or fewer rows in the sheet.
>
> I want to have a macro delete entries from both columns
> based on ranked aging of the date/time stamp. Leave the
> X newest entries (such as 3 or 5 or 10) and delete others.
>
> I started to code this but ran into trouble. Here
> is what I have. Can someone help me get this to work?
> It would be much appreciated.
>
> '--------------
> Dim cell As Range
> Dim testI As Range
>
> ' Some unrelated stuff deleted ...
>
> For Each cell In Range("G2:G500")
> If cell <> "" Then
> Set testI = cell.Offset(0, 2)
> Debug.Print testI
> If Not Application.WorksheetFunction.Rank(testI, _
> Range("G2:G500")) < 6 Then
> Range(cell, testI).Clear
> End If
> End If
> Next 'cell
> '--------------
>
> Thanks for any help, guys.
>
> =dman=
>

 
Reply With Quote
 
Dallman Ross
Guest
Posts: n/a
 
      3rd Oct 2008
Clarifying, when I try to run my code below I get "Run-time
error '1004': Unable to get the Rank property of the WorksheetFunction
class." What am I doing wrong, please? Can you help?

----------------
In <gc3gvs$i9o$(E-Mail Removed)>, Dallman Ross <dman@localhost.>
spake thusly:

> I have two columns, G and I, that I used together. G has a number
> in it and I has a date/time stamp. Here is an example:
>
> 18.32 10/2/08 14:49
> 19.99 9/26/08 21:36
>
>
> Not all the cells are filled in. Many are blank. There
> are about 200 or fewer rows in the sheet.
>
> I want to have a macro delete entries from both columns
> based on ranked aging of the date/time stamp. Leave the
> X newest entries (such as 3 or 5 or 10) and delete others.
>
> I started to code this but ran into trouble. Here
> is what I have. Can someone help me get this to work?
> It would be much appreciated.
>
> '--------------
> Dim cell As Range
> Dim testI As Range
>
> ' Some unrelated stuff deleted ...
>
> For Each cell In Range("G2:G500")
> If cell <> "" Then
> Set testI = cell.Offset(0, 2)
> Debug.Print testI
> If Not Application.WorksheetFunction.Rank(testI, _
> Range("G2:G500")) < 6 Then
> Range(cell, testI).Clear
> End If
> End If
> Next 'cell
> '--------------
>
> Thanks for any help, guys.
>
> =dman=

 
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
Rank a column but not include some cells =?Utf-8?B?UGlsbGFy?= Microsoft Excel Misc 10 8th Oct 2006 05:33 AM
Rank with array of cells Mad Ant Microsoft Excel Discussion 4 25th Oct 2005 01:05 PM
populating cells using rank in other sheet =?Utf-8?B?U3RlZmFuIEdpbGRlbWVpc3Rlcg==?= Microsoft Excel Worksheet Functions 2 14th Nov 2003 09:48 PM
RANK function without the cells being sorted?? PZ Straube Microsoft Excel Worksheet Functions 3 14th Oct 2003 01:03 PM
copmapre and rank cells MikeD Microsoft Excel Programming 2 22nd Aug 2003 05:35 AM


Features
 

Advertising
 

Newsgroups
 


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