Thread: [Solved] Macro to sort columns
View Single Post
 
Old 08-17-2016, 06:40 AM
SerenityNetworks SerenityNetworks is offline Windows 10 Office 2016
Advanced Beginner
 
Join Date: May 2005
Location: Allen, Texas, USA
Posts: 37
SerenityNetworks
Question 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
Reply With Quote