Forum Discussion
ksp_87
Mar 13, 2018Copper Contributor
Excel sort - Smaller to Largest
Hi,
I have the below table and i am trying to sort the data from small to larger for all the columns at the same time. If i try to sort, only column A is getting sorted and there is no change w...
ksp_87
Mar 13, 2018Copper Contributor
Thanks for responding. I have 2000 columns and it will take loads of
time to do that individually. Looking if it can be done through macro
Haytham Amairah
Mar 14, 2018Silver Contributor
Hi,
Sorry for the delay in reply!
I've written this macro for you:
Sub SortingMacro()
'Sort each column individually in ascending order
'Written by Haytham Amairah
'Last Updated: 3/14/2018
Application.ScreenUpdating = False
On Error Resume Next
For Each col In ActiveWorkbook.ActiveSheet.UsedRange.Columns
col.EntireColumn.Select
r = col.EntireColumn.Address
ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort.SortFields.Clear
ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort.SortFields.Add Key:=Range(r), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort
.SetRange Range(r)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Next
Range("A1").Select
On Error GoTo 0
Application.ScreenUpdating = True
End Sub
Please test it and refer back to me if you have any feedback.
Hope that helps
Haytham