View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Sort reference is not valid

I would drop the .selects

with Worksheets("75851_Plasticity_All")
with .Range("A:B")
.Sort Key1:=.columns(2), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
end with
end with

And if you know if your data has headers, you don't have to let excel guess.
I'd put xlno or xlyes as the Header parm.

Freddy wrote:

I have read other post concerning sorting with macros, but I cannot find any
information as to why my code will not work. I am receiving the error message

€œRun-time error €˜1004:
The sort reference is not valid. Make sure that its within the data you
want to sort, and the first Sort By box isnt the same or blank.€

The sort code and the worksheet selection code is below. Does anyone have
any suggestions?

Thanks!

Worksheets("75851_Plasticity_All").Range("A:B").Se lect
Selection.Sort Key1:=Range("A2"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal


--

Dave Peterson