I am suddenly getting a 400 error while trying to sort data on a worksheet, and I can’t figure out why. Here’s my code:
The 400 error happens on the last line.
I stepped through the code and watched the variables, and here is what they are equal to:
LastColumn = “BU”
LastRow = 5
SortRange = “A2:BU5”
KeySortCol = “A2:A5”
I had something similar working in an earlier version of this workbook, so I can’t figure out what I did that would suddenly cause the 400 error. Anyone have any ideas?
Code:
Dim SortRange As String
Dim KeySortCol As String
Dim LastColumn As String
Dim LastRow as Integer
ThisWorkbook.Sheets("Sheet 2").Activate
LastColumn = ThisWorkbook.Sheets("Sheet 5").Range("B80").Value
LastRow = ThisWorkbook.Sheets("Sheet 2").Cells(Rows.Count, 1).End(xlUp).Row
SortRange = "A2:" & LastColumn & LastRow
KeySortCol = "A2:A" & LastRow
ThisWorkbook.Sheets("Sheet 2").Range(SortRange).Sort key1:=Range(KeySortCol), order1:=xlAscending, Header:=xlNo
The 400 error happens on the last line.
I stepped through the code and watched the variables, and here is what they are equal to:
LastColumn = “BU”
LastRow = 5
SortRange = “A2:BU5”
KeySortCol = “A2:A5”
I had something similar working in an earlier version of this workbook, so I can’t figure out what I did that would suddenly cause the 400 error. Anyone have any ideas?