Today I found a sort sub routine on in this forum that allows me to sort columns left to right. To test it out, I created a simple sub routine (see below) and it worked just fine.
Sub Test()
Worksheets("CommonData").Sort.SortFields.Clear
Worksheets("CommonData").Range("E3:X24").Sort Key1:=Range("E3:X3"), Order1:=xlAscending, Orientation:=xlLeftToRight
End Sub
I copied and inserted the code into a large subroutine and upon running it, I was confronted with an error code. Below is an excerpt of that code which includes the above-mentioned code along with what immediately precedes it and the error code I got.
' Note: The following sort first sorts a table from Top to Bottom in Ascending order.
Dim rng1 As Range
Dim ws1 As Worksheet
Set ws1 = Worksheets("CommonData")
Set rng1 = ws1.Range("B5:X24")
ws1.Sort.SortFields.Clear
With rng1
.Sort Key1:=ws1.Range("B5"), Order1:=xlAscending, _
Header:=xlNo
End With
''' TESTING OUT LEFT TO RIGHT SORT OF COMMONDATA TABLE
' Note: The following sort is intended to take the same table sorted above but then also sorts it from Left To Right.
Worksheets("CommonData").Sort.SortFields.Clear
Worksheets("CommonData").Range("E3:X24").Sort Key1:=Range("E3:X3"), Order1:=xlAscending, Orientation:=xlLeftToRight
Upon receiving this message, I click on Debug and the following line is highlighted:
Worksheets("CommonData").Range("E3:X24").Sort Key1:=Range("E3:X3"), Order1:=xlAscending, Orientation:=xlLeftToRight
If anyone has any thoughts as to why this is happening or how to correct it, I would greatly appreciate your help.
Thank you
Sub Test()
Worksheets("CommonData").Sort.SortFields.Clear
Worksheets("CommonData").Range("E3:X24").Sort Key1:=Range("E3:X3"), Order1:=xlAscending, Orientation:=xlLeftToRight
End Sub
I copied and inserted the code into a large subroutine and upon running it, I was confronted with an error code. Below is an excerpt of that code which includes the above-mentioned code along with what immediately precedes it and the error code I got.
' Note: The following sort first sorts a table from Top to Bottom in Ascending order.
Dim rng1 As Range
Dim ws1 As Worksheet
Set ws1 = Worksheets("CommonData")
Set rng1 = ws1.Range("B5:X24")
ws1.Sort.SortFields.Clear
With rng1
.Sort Key1:=ws1.Range("B5"), Order1:=xlAscending, _
Header:=xlNo
End With
''' TESTING OUT LEFT TO RIGHT SORT OF COMMONDATA TABLE
' Note: The following sort is intended to take the same table sorted above but then also sorts it from Left To Right.
Worksheets("CommonData").Sort.SortFields.Clear
Worksheets("CommonData").Range("E3:X24").Sort Key1:=Range("E3:X3"), Order1:=xlAscending, Orientation:=xlLeftToRight
Upon receiving this message, I click on Debug and the following line is highlighted:
Worksheets("CommonData").Range("E3:X24").Sort Key1:=Range("E3:X3"), Order1:=xlAscending, Orientation:=xlLeftToRight
If anyone has any thoughts as to why this is happening or how to correct it, I would greatly appreciate your help.
Thank you