I've found a few articles that I thought would help me sort my sheet via VBA (like VBA Excel sort range by specific column), but I just can't get them to work.
When I'm sorting, I have a number of worksheets open, which I think may be complicating the issue. But when I set the ranges I'm using the sort, I select the worksheet, so I just don't know.
If you look at the code, you can see that I have lots of variables defined that might be useful, so feel free to use any of those that would be helpful.
'These are created elsewhere as Public, or passed into Sub
Dim SourceSheet As Worksheet
Dim MyWB As String
Dim MyWS As String
Dim ColNum As Integer
Dim SourceFirstRow As Integer
Dim SourceLastRow As Integer
Dim FinalFirstRow As Integer
Dim FinalFirstColumn As Integer
Dim FinalLastColumn As Integer
'These are created and used in the subroutine
Dim FinalSheet As Worksheet
Dim AllCells As Range
Dim SortColumn As Range
Dim SourceRow As Integer
Dim CurrentFinalRow As Integer
'These are actually set elsewhere and passed in, shown here for example
Set SourceSheet = ThisWorkbook.Worksheets(1)
Set SourceFirstRow = 2
Set SourceLastRow = 15
Set MyWB = "DataFile"
Set MyWS = "Data"
Set FinalFirstRow = 2
Set FinalFirstColumn = 1
Set FinalLastColumn = 20
Set ColNum = 4
'These is the relevant code from the subroutine
Set FinalSheet = Workbooks(MyWB).Worksheets(MyWS)
Set CurrentFinalRow = FinalFirstRow
Set AllCells = FinalSheet.Cells
Set SortColumn = FinalSheet.Columns(ColNum)
For SourceRow = SourceFirstRow To SourceLastRow
'Fill in a whole bunch of data into the rows and columns on the final sheet
'not all sourcerows are transferred
CurrentFinalRow = CurrentFinalRow + 1 'Sets it ready for the next blank line to be filled
Next SourceRow
Range(AllCells & CurrentFinalRow - 1).Sort key1:=Range(SortColumn & CurrentFinalRow - 1), order1:=xlAscending, Header:=xlYes