I have a macro who reads CSV files (22 in this test, but they are more) and put data starting on column 9 ("I").
I sort those columns using copy paste transpose, but I don't like this, I'm looking for a better way to sort the titles.
My sort code is:
I sort those columns using copy paste transpose, but I don't like this, I'm looking for a better way to sort the titles.
My sort code is:
Code:
Sub SortTitles()
Range("I1:AD1").Copy
Range("AF1").PasteSpecial Paste:=xlPasteAll, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=True
With ActiveWorkbook.Worksheets("Global").Sort
.SortFields.Clear
.SortFields.Add Key:=Range("AF1:AF22"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
.SetRange Range("AF1:AF22")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Selection.Copy
Range("I1").PasteSpecial Paste:=xlPasteAll, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=True
Columns("AF").Delete xlToLeft
End Sub