Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 390
Default Delete cells below a certain rank

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=
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Delete cells below a certain rank

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=

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 390
Default Delete cells below a certain rank

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 , 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
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
rank the numbers / range of data using 'RANK' and 'ABS' KP Excel Worksheet Functions 1 March 8th 08 05:50 PM
Rank a column but not include some cells Pillar Excel Discussion (Misc queries) 10 October 8th 06 05:33 AM
RANK, duplicate ranking but no gaps in rank arron laing Excel Worksheet Functions 4 June 14th 06 07:57 AM
Rank items, select one start date, have remaining dates follow based on rank rob normerica Excel Discussion (Misc queries) 1 August 15th 05 09:36 PM
copmapre and rank cells MikeD Excel Programming 2 August 22nd 03 05:35 AM


All times are GMT +1. The time now is 11:02 PM.

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"