G
Guest
Hi all,
The following macro sorts dates and corresponding information (columns A-Q
and S-AI) in ascending order:
I can successfullly run it on Sheet1. Sheet1 does not have any headers and
the data begins on Row 1.
I was thinking I might want to run the also on Sheet2 as well. So I made a
second copy and changed the Column and Row references, but it doesn't seem to
work. Furthermore, I added the syntax "ActiveSheet" at the beginning
thinking that this would make it run on any sheet I had selected.
Here's the code:
'Successfully runs on Sheet1:
Public Sub Sort()
ActiveSheet.Columns("A:Q").Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Key2:=Range("B1") _
, Order2:=xlAscending, Key3:=Range("C1"), Order3:=xlAscending,
Header:= _
xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
ActiveWindow.SmallScroll ToRight:=18
ActiveSheet.Columns("S:AI").Select
Selection.Sort Key1:=Range("S1"), Order1:=xlAscending, Key2:=Range("T1") _
, Order2:=xlAscending, Key3:=Range("U1"), Order3:=xlAscending,
Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
Range("a1").Select
End Sub
'Returns a Run-time error saying the cells must be identically sized
(referring to rows 1-4 (I think) when I try to run this on Sheet2
Public Sub Sort2()
ActiveSheet.Columns("A:Q").Select
Selection.Sort Key1:=Range("A5"), Order1:=xlAscending, Key2:=Range("B5") _
, Order2:=xlAscending, Key3:=Range("C5"), Order3:=xlAscending,
Header:= _
xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
ActiveWindow.SmallScroll ToRight:=18
ActiveSheet.Columns("S:AI").Select
Selection.Sort Key1:=Range("S5"), Order1:=xlAscending, Key2:=Range("T5") _
, Order2:=xlAscending, Key3:=Range("U5"), Order3:=xlAscending,
Header:= _
xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
Range("a1").Select
End Sub
Any ideas what I'm doing wrong for trying to run this on Sheet2? I have
these saved in Module1 in the Module folder.
Thanks so much,
Sharon
The following macro sorts dates and corresponding information (columns A-Q
and S-AI) in ascending order:
I can successfullly run it on Sheet1. Sheet1 does not have any headers and
the data begins on Row 1.
I was thinking I might want to run the also on Sheet2 as well. So I made a
second copy and changed the Column and Row references, but it doesn't seem to
work. Furthermore, I added the syntax "ActiveSheet" at the beginning
thinking that this would make it run on any sheet I had selected.
Here's the code:
'Successfully runs on Sheet1:
Public Sub Sort()
ActiveSheet.Columns("A:Q").Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Key2:=Range("B1") _
, Order2:=xlAscending, Key3:=Range("C1"), Order3:=xlAscending,
Header:= _
xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
ActiveWindow.SmallScroll ToRight:=18
ActiveSheet.Columns("S:AI").Select
Selection.Sort Key1:=Range("S1"), Order1:=xlAscending, Key2:=Range("T1") _
, Order2:=xlAscending, Key3:=Range("U1"), Order3:=xlAscending,
Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
Range("a1").Select
End Sub
'Returns a Run-time error saying the cells must be identically sized
(referring to rows 1-4 (I think) when I try to run this on Sheet2
Public Sub Sort2()
ActiveSheet.Columns("A:Q").Select
Selection.Sort Key1:=Range("A5"), Order1:=xlAscending, Key2:=Range("B5") _
, Order2:=xlAscending, Key3:=Range("C5"), Order3:=xlAscending,
Header:= _
xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
ActiveWindow.SmallScroll ToRight:=18
ActiveSheet.Columns("S:AI").Select
Selection.Sort Key1:=Range("S5"), Order1:=xlAscending, Key2:=Range("T5") _
, Order2:=xlAscending, Key3:=Range("U5"), Order3:=xlAscending,
Header:= _
xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
Range("a1").Select
End Sub
Any ideas what I'm doing wrong for trying to run this on Sheet2? I have
these saved in Module1 in the Module folder.
Thanks so much,
Sharon