Hi
I'm having some problems with a custom sort in a macro I've made.
Below is the extract of the specific piece of code, the error occurs on the penultimate line where it tries to apply the sort.
This part of the code is right at the end of the macro (it's rather large hence not posting all of it). The weird thing is that if I run the macro without the sort, and then run the sort as a separate macro it works without a problem. I thought it might be something to do with having automatic calculations turned off whilst running but this doesn't seem to be the case.
Any help would be very much appreciated! I'm sure it's something obvious I'm missing...
I'm having some problems with a custom sort in a macro I've made.
Below is the extract of the specific piece of code, the error occurs on the penultimate line where it tries to apply the sort.
This part of the code is right at the end of the macro (it's rather large hence not posting all of it). The weird thing is that if I run the macro without the sort, and then run the sort as a separate macro it works without a problem. I thought it might be something to do with having automatic calculations turned off whilst running but this doesn't seem to be the case.
Any help would be very much appreciated! I'm sure it's something obvious I'm missing...
Code:
Cells.Select
ActiveWorkbook.Worksheets("Console").sort.SortFields.Clear
ActiveWorkbook.Worksheets("Console").sort.SortFields.Add Key:=Range("A1:A1048576"), _
SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
"Custom 1,Custom 2,Custom 3,Custom 4,Custom 5,Custom 6" _
, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Console").sort.SortFields.Add Key:=Range( _
"H1:H1048576"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Console").sort.SortFields.Add Key:=Range( _
"CF1:CF1048576"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
ActiveWorkbook.Worksheets("Console").sort.SortFields.Add Key:=Range( _
"CG1:CG1048576"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
ActiveWorkbook.Worksheets("Console").sort.SortFields.Add Key:=Range( _
"CH1:CH1048576"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
ActiveWorkbook.Worksheets("Console").sort.SortFields.Add Key:=Range( _
"CI1:CI1048576"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
ActiveWorkbook.Worksheets("Console").sort.SortFields.Add Key:=Range( _
"CJ1:CJ1048576"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
ActiveWorkbook.Worksheets("Console").sort.SortFields.Add Key:=Range( _
"CK1:CK1048576"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
ActiveWorkbook.Worksheets("Console").sort.SortFields.Add Key:=Range( _
"CL1:CL1048576"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
ActiveWorkbook.Worksheets("Console").sort.SortFields.Add Key:=Range( _
"CM1:CM1048576"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
ActiveWorkbook.Worksheets("Console").sort.SortFields.Add Key:=Range( _
"CN1:CN1048576"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
ActiveWorkbook.Worksheets("Console").sort.SortFields.Add Key:=Range( _
"CO1:CO1048576"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
ActiveWorkbook.Worksheets("Console").sort.SortFields.Add Key:=Range( _
"CP1:CP1048576"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
ActiveWorkbook.Worksheets("Console").sort.SortFields.Add Key:=Range( _
"CQ1:CQ1048576"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
ActiveWorkbook.Worksheets("Console").sort.SortFields.Add Key:=Range( _
"CR1:CR1048576"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
ActiveWorkbook.Worksheets("Console").sort.SortFields.Add Key:=Range( _
"CS1:CS1048576"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
With ActiveWorkbook.Worksheets("Console").sort
.SetRange Columns("A:CV")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With