Hello,
I've been trying to find a way to sort data that gets added to a sheet with VBA. What it needs to do is pretty straight forward, so I'll just give an example of what I'd like it to do :
I'm trying to get data that looks like so :
And have the dates sort from left to right, oldest to newest; but then have it move the three columns below each date in tandem with it. So, taking the above example and turn it into this :
So I have the general idea where I can sort the dates with a code like so :
But I'm not so sure what lies beyond this to get the desired results. Hopefully it's not too complicated
Just to state it; there is no more or less to this specific sheet other than the fact that the idea is to have data constantly build up in it over time. So the date will always be in row 1. 1st, 2nd, and 3rd will always be in row 2 in that order. The rest of the numbers are quantities that should stay in order with it's respective date and 1st, 2nd, or 3rd entry.
Any help would truly be appreciated!
I've been trying to find a way to sort data that gets added to a sheet with VBA. What it needs to do is pretty straight forward, so I'll just give an example of what I'd like it to do :
I'm trying to get data that looks like so :
And have the dates sort from left to right, oldest to newest; but then have it move the three columns below each date in tandem with it. So, taking the above example and turn it into this :
So I have the general idea where I can sort the dates with a code like so :
VBA Code:
Sub testsort()
Range(Cells(1, 1), Cells(1, Columns.Count).End(xlToLeft)).Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add2 Key:=Range(Cells(1, 1), Cells(1, Columns.Count).End(xlToLeft)) _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range(Cells(1, 1), Cells(1, Columns.Count).End(xlToLeft))
.Header = xlNo
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
End Sub
But I'm not so sure what lies beyond this to get the desired results. Hopefully it's not too complicated
Just to state it; there is no more or less to this specific sheet other than the fact that the idea is to have data constantly build up in it over time. So the date will always be in row 1. 1st, 2nd, and 3rd will always be in row 2 in that order. The rest of the numbers are quantities that should stay in order with it's respective date and 1st, 2nd, or 3rd entry.
Any help would truly be appreciated!