Forum Discussion

johanvl's avatar
johanvl
Copper Contributor
Apr 27, 2023
Solved

sort all columns

Hello, i have a sheet with 5000 columns and 7 rows. These are filled with numbers. I would like to sort every column from lowest to highest order. How can i achieve this? 
  • NikolinoDE's avatar
    Apr 27, 2023

    johanvl 

    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 Sub

    I hope this helps!

     

Resources