S
standard_guy
Good morning,
I have a daily file where the user goes and updates some queries from an
AS400, then runs my macro in a report speadsheet to format the new day's
info. In the course of the macro, I do the following sort. On a new day,
the sort from what I can tell doesn't work, but then if you run it again it
works like I want it to work. Is there something I need to reset when I
start to make the sort work the first time? I do a lot of other things after
the sort and somewhere in there I must do what I need to do but I haven't
been able to figure out what it is. (I tried it with and without clearing
the sort fields first and that doesn't matter.
Thanks.
Columns("A").Select
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add
Key:=Range("P21000" _
), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add
Key:=Range("I2:I1000" _
), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add
Key:=Range("B2:B1000" _
), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet2").Sort
.SetRange Range("A11000")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
I have a daily file where the user goes and updates some queries from an
AS400, then runs my macro in a report speadsheet to format the new day's
info. In the course of the macro, I do the following sort. On a new day,
the sort from what I can tell doesn't work, but then if you run it again it
works like I want it to work. Is there something I need to reset when I
start to make the sort work the first time? I do a lot of other things after
the sort and somewhere in there I must do what I need to do but I haven't
been able to figure out what it is. (I tried it with and without clearing
the sort fields first and that doesn't matter.
Thanks.
Columns("A").Select
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add
Key:=Range("P21000" _
), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add
Key:=Range("I2:I1000" _
), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add
Key:=Range("B2:B1000" _
), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet2").Sort
.SetRange Range("A11000")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With