Excel VB Custom Sort question

  Desert Andy 12:19 PM 23 Nov 12
Locked

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

Advertisement

This thread is now locked and can not be replied to.

How to get free stuff for Android: Amazon Underground offers genuinely free Android apps and free…

1995-2015: How technology has changed the world in 20 years

Swedish schoolkids use Minecraft to redesign Stockholm city centre

Apple's special event invitations decoded: A look back at 13 of Apple's most cryptic invites