View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Sorting UsedRange of a Worksheet

Ryan,

The problem is that when you specify the key as Range("L3"), that range
refers the the L3 on the *active* sheet, which is not going to be the wks
sheet. Try

Sub Sort()
For Each wks In Worksheets
With wks
.UsedRange.Sort Key1:=.Range("L3"), Order1:=xlAscending, _
Key2:=.Range("A3"), Order2:=xlAscending, Header:=xlGuess
End With
Next wks

End Sub

Note that there is a leading period before UsedRange,Range("A3"), and
Range("L3"). These are required for the With statement.


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2008
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


"RyanH" wrote in message
...
How can I sort only the UsedRange of each Worksheet in a workbook? This
is
what I have so far and it will not let me.

Sub Sort ()

For Each wks In Worksheets
wks.UsedRange.Sort Key1:=Range("L3"), Order1:=xlAscending, _
Key2:=Range("A3"), Order2:=xlAscending,
Header:=xlGuess
Next wks

End Sub