Tech Helproom
It's free to register, to post a question or to start / join a discussion
Excel VB Custom Sort question
Likes # 0
Posted November 23, 2012 at 12:19PM
Hi
I have recorded the following macro
Range("C4:K10").Select ActiveWorkbook.Worksheets("GRID").Sort.SortFields.Clear ActiveWorkbook.Worksheets("GRID").Sort.SortFields.Add Key:=Range("C5:C10"), _ SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:="MC", _ DataOption:=xlSortNormal With ActiveWorkbook.Worksheets("GRID").Sort .SetRange Range("C4:K10") .Header = xlYes .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With
When I try and put it into a subroutine code
ActiveWorkbook.Worksheets(SheetName).Sort.SortFields.Clear ActiveWorkbook.Worksheets(SheetName).Sort.SortFields.Add Key:=Range("C5:K10"), _ SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:="MC", DataOption:=xlSortNormal With ActiveWorkbook.Worksheets(SheetName).Sort .SetRange Range("C5:K10") .Header = xlNo .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With
Unfortunately i get a runtime error 10004 with the message 'The sort reference is not valid.
Can anyone help please. I have it written as a subroutine because I want to change the cutom sort field .
Many thanks
Reply to this topic
This thread has been locked.
Check out PC Advisor's other tech forums
Top 5 Most Popular
-
New Xbox One release date, specs, features and price in UK
-
Samsung Galaxy S4 vs Apple iPhone 5 comparison review
-
Galaxy S4 vs BlackBerry Z10 comparison review - which is best, the Samsung or the BlackBerry?
-
Best cases and covers for the new iPad: protect your tablet in style
-
What’s the best mobile OS: iOS, Android, Windows Phone 8 or BlackBerry 10?



