Share via

VBA Sort Issue

Anonymous
2012-07-30T16:51:12+00:00

I have a "new" macro that I recently developed from an existing macro.  In the original macro, the following code was used to sort data:

Range("A5").Select

Selection.Sort Key1:=Range("AL5"), Order1:=xlAscending, Key2:=Range("K5"), Order2:=xlAscending, Key3:=Range("L5"), Order3:=xlAscending, Header:= _

xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

This code has worked for years without any problems in the "old" macro.  Now in the "new" macro, some users, but not all, will get the following run-time error '1004' The sort reference is not valid.  Make sure that it's within the data you want to sort, and the first Sort By isn't the same or blank.

I can't figure out what is going on.  It only happens to some users and not to others.  Can it be a 2003 / 2007 issue?

Thanks for the help....

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-07-30T17:25:55+00:00

That code should be supported in Excel 2007.

You might try

Range("A5").CurrentRegion.Select

Selection.Sort Key1:=Range("AL5"), Order1:=xlAscending, Key2:=Range("K5"), Order2:=xlAscending, Key3:=Range("L5"), Order3:=xlAscending, Header:= _

xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

and see if that is anymore robust

--

Regards,

Tom Ogilvy

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful