Macro to sort columns
I have an array of about 340 columns wide and 16 rows long. I need to sort (ascending) each column separately (select column, sort a-z, continue with current selection). It will be quite tedious to do the sorting manually for 340 columns, so I was looking to build a macro to do it for me.
I've tried the following, but can't get it debugged. Of course then I also need to add in a loop to go to the next column, repeat, and eventually end the loop when out of columns with content to sort.
Any help in creating the macro will be appreciated, else I'm back to just doing each column manually.
Thanks in advance,
Andrew
Sub DoIt()
ActiveWorkbook.Worksheets("SortIt").Sort.SortField s.Clear
ActiveWorkbook.Worksheets("SortIt").Sort.SortField s.Add Key:=Range(ActiveCell.EntireColumn.Cells(1)), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("SortIt").Sort
.SetRange Range(Selection.EntireColumn)
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
|