Forum Discussion
sort all columns
- Apr 27, 2023
You can sort all columns in your sheet from lowest to highest order using the following steps:
Select the range of cells that contains your data (all 5000 columns and 7 rows).
Click on the "Data" tab in the Excel Ribbon.
In the "Sort & Filter" group, click on the "Sort" button.
In the "Sort" dialog box, make sure that the "My data has headers" checkbox is unchecked.
In the "Sort By" section, choose the column you want to sort by (it doesn't matter which column you choose since you want to sort all columns).
In the "Sort On" section, choose "Values".
In the "Order" section, choose "Smallest to Largest".
Click "OK".
Excel will now sort each column in your sheet from lowest to highest order. This may take some time to complete, depending on the size of your data set. Once the sorting is complete, your data will be arranged in ascending order within each column.
Alternatively, if you are familiar with VBA, you can use a macro to automate this process. Here is an example macro that sorts all columns in ascending order:
Sub SortAllColumns() Dim lastRow As Long Dim lastColumn As Long Dim i As Long 'Find the last row and column with data in the active sheet lastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row lastColumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column 'Loop through each column and sort it For i = 1 To lastColumn Range(Cells(1, i), Cells(lastRow, i)).Sort key1:=Cells(1, i), order1:=xlAscending, Header:=xlNo Next i End SubI hope this helps!
thanks for answering.
I tried the sort function from excel as you mentionned, but then only the first column is sorted, rest of columns changed order but not correctly.
I am no VBA specialist, so i copy pasted your code, ran it and this worked.
thanks a lot NikolinoDE
I wish you continued success with Excel!