Thread: Range Selection
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Don Guillett Don Guillett is offline
external usenet poster
 
Posts: 10,124
Default Range Selection

This uses cell b2 (cells(2,2) as the sort key. If you want col A use
cells(2,1)

Sub sortarea()
lc = Cells(1, Columns.Count).End(xlToLeft).Column
lr = Cells.Find("*", Cells(Rows.Count, Columns.Count) _
, , , xlByRows, xlPrevious).Row
'MsgBox lc
'MsgBox lr
Range(Cells(1, 1), Cells(lr, lc)).Sort _
Key1:=Cells(2, 2), Order1:=xlAscending, Header:=xlYes, _
MatchCase:=False, Orientation:=xlTopToBottom
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"WLMPilot" wrote in message
...
I am trying to select a variable range, beginning in column A and ending in
the furtherest column to the right being used AND last row used.

There are three factors to remember:
1) The actual beginning point (upper leftmost cell) may change as I
insert/delete
rows above the data to be sorted. The first cell in column A for the
sort range
is located below the header FREQ.
2) The number of rows down will increase as data is added.
3) The number of columns used may increase if I determine there are other
items I need to calculate/input.

Currently, I am using columns A-R. The column headers are on row 8, which
may increase/decrease based on item #1 above.

One other quick question:
I believe I have the sort code I need. My question is this: After the
range is selected, I believe the first part of the sort code is
"Selection:Sort" (without quotes). Is this correct?

Thanks for your help!

Les