tommyleinen
Board Regular
- Joined
- Aug 22, 2009
- Messages
- 74
Hi there, I wonder if anyone can help, I have part of a macro getting run-time error '1004', trying to sort columns J:K in a workbook with multiple sheets of similar format.
Here is the code that gets stuck at ".Apply":
Columns("J:K").Select
Application.CutCopyMode = False
ActiveSheet.Sort.SortFields.Clear
ActiveSheet.Sort.SortFields.Add Key:=Range( _
"J1:K9500"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With ActiveSheet.Sort
.SetRange Range("J1:K9500")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
I am using .Activesheet, because the macro is to be able to be used seperately on different sheets, other wise I will need to have a seperate macro per sheet, which I don't want to have to do - makes it easier for changing the macro in future.
Anyone any ideas? Thanks in advance.
Here is the code that gets stuck at ".Apply":
Columns("J:K").Select
Application.CutCopyMode = False
ActiveSheet.Sort.SortFields.Clear
ActiveSheet.Sort.SortFields.Add Key:=Range( _
"J1:K9500"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With ActiveSheet.Sort
.SetRange Range("J1:K9500")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
I am using .Activesheet, because the macro is to be able to be used seperately on different sheets, other wise I will need to have a seperate macro per sheet, which I don't want to have to do - makes it easier for changing the macro in future.
Anyone any ideas? Thanks in advance.