View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Robert McCurdy Robert McCurdy is offline
external usenet poster
 
Posts: 102
Default Sort Without Knowing Last Cell

A few questions:
Does your table have headers in row 2?
Is your table clear of internal blank rows?
Are there other tables or data below your desired sortable range/table?

Assuming the answers are, Yes, Yes, No (as it should), then:

Sub Dsort()
Dim SortRng As Range
Set SortRng = Range("E2:G" & Rows.Count)
SortRng.Sort Key1:=Range("G2"), Order1:=xlDescending, Header:=xlYes, _
Key2:=Range("E2"), Order2:=xlAscending, Header:=xlYes, _
Key3:=Range("F2"), Order3:=xlAscending, Header:=xlYes
End Sub


Regards
Robert McCurdy
"Paul Black" wrote in message oups.com...
Hi everyone,

I have a program that outputs columns of values to a worksheet.
I have titles in row 2 and the values start in columns "E3:G?",
"I3:L?" etc.
I would like to sort the values but I don't know what the last row
will be.
Here is an example for columns "E3:G?" ...

Range("E3:G?").Select
Selection.Sort Key1:=Range("G3"), Order1:=xlDescending,
Key2:=Range("E3") _
, Order2:=xlAscending, Key3:=Range("F3"), Order3:=xlAscending

.... with the ? is the unknown number to sort down to.

Thanks in Advance.
All the Best.
Paul