View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jef Gorbach[_2_] Jef Gorbach[_2_] is offline
external usenet poster
 
Posts: 65
Default Last row + rank help

On Feb 9, 10:50*am, Opal wrote:
Thank you Don....

Is this a function that I put into the VBA project?
How do I call it on the work sheet.

What I mean by rank, is I need to find the
last row of data on the sheet (once a week)
and rank the values in the range as these will
change week by week - I update weekly
via pivot table.


Sounds like you're new to macros so I'll step thru this from the very
beginning.
From your worksheet, press Alt+11 to bring up the macro/vba editor
then cut/paste everything below my dashed line there.
To run it, press alt+F from your worksheet and choose to run
MacroTryThis.

Rather than risk messing up your data, it first copies your first
worksheet to a new tab named Ranked Values, then selects of all of the
cells, sorting ("ranking") column B from smallest to largest
("ascending").
---------------------------------------------------------
Sub MacroTryThis()
'delete the "Ranked Values" worksheet if it already exists
Application.DisplayAlerts = False
On Error Resume Next
Worksheets("Ranked Values").Delete
Application.DisplayAlerts = True
On Error GoTo 0

'copy sheet1 to a new tab then name it Ranked Values
Sheets("Sheet1").Select
Sheets("Sheet1").Copy After:=Sheets(1)
ActiveSheet.Name = "Ranked Values"

'sort ("rank") column B from smallest to largest
Cells.Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

'end with the cursor at cell B2
Range("B2").Select
End Sub