How to Sort Values By Columns in Excel
Learn multiple Excel methods to sort values by columns with step-by-step examples and practical applications.
How to Sort Values By Columns in Excel
Why This Task Matters in Excel
Sorting information is one of the most routine activities in spreadsheet work, but most discussions, help pages, and coffee-break conversations focus on sorting rows. Rows appear to be the natural orientation for transactional data, so we get used to clicking Data ➜ Sort and watching entire rows shuffle up or down. Yet many real-world worksheets store figures horizontally: one row per project with twelve monthly columns, a single row of exam scores belonging to one student, or a row of revenues for separate regions. Whenever you need to quickly rank, highlight, or re-order those horizontal numbers, row-based sorting falls short. Learning to sort values by columns fills that gap.
Consider a sales manager who keeps a dashboard where every row represents a product and every column holds sales for a month. She wants to instantly know each product’s strongest months by re-ordering the month columns from highest to lowest sales. Another common scenario is an HR analyst comparing annual appraisal ratings across employees, where ratings sit across columns. Sorting each employee’s ratings reveals personal highs and lows at a glance. Education, finance, sports analytics, and any field that stacks comparable numbers horizontally share the same need.
Excel has a rich toolbox for this task. Dynamic array functions such as SORT and SORTBY can reorder values across columns with a single formula in modern Microsoft 365. TRANSPOSE lets us flip the orientation so classic row-sorting works even in older versions. SMALL, LARGE, INDEX, MATCH, and helper rows allow robust, version-agnostic formulas when dynamic arrays are unavailable. Power Query can reshape and sort entire tables horizontally while preserving refreshability. The key is selecting the approach that balances compatibility, ease of maintenance, and workbook performance.
Ignoring horizontal sort skills costs time and insight. Analysts spend precious hours manually copying, pasting, and re-sorting every time the underlying numbers change. Decisions get delayed, and errors creep in when manual steps go unnoticed. Mastering column-based sorting integrates seamlessly with pivot tables, conditional formatting, and dashboards, making your analytical workflows faster and more reliable.
Best Excel Approach
The best all-round method for sorting values by columns in modern Excel (Microsoft 365 or Excel 2021) is the dynamic array function SORT with its dimension argument. Introduced in 2020, the function sorts an array either by rows (default) or by columns (when dimension is set to 2). Because it recalculates automatically, it remains fully dynamic—any time source data changes, the sorted output updates instantly without macros or manual refreshes.
Use SORT when:
- You have Microsoft 365 / Excel 2021 or later
- You want a formula solution that autoupdates
- You only need to sort by one criterion (value) across columns
Prerequisites: your data must be in a contiguous horizontal range, and you must place the formula where there is enough blank space to spill the sorted result.
Logic overview: SORT inspects the supplied array, applies an ascending or descending order, and then rearranges entire columns when dimension = 2.
Syntax (key parameters explained below):
=SORT(array, [sort_index], [sort_order], [by_col])
- array: the horizontal range you want to sort
- sort_index: which column to sort by (ignored when sorting by column orientation)
- sort_order: 1 for ascending, -1 for descending
- by_col: TRUE or 1 tells Excel to sort by columns rather than rows
Example descending column sort:
=SORT([B2:M2], 1, -1, TRUE)
Alternatives exist:
- TRANSPOSE + SORT
Flip the row into a column, sort, then flip back.
=TRANSPOSE(SORT(TRANSPOSE([B2:M2]), 1, -1))
- SMALL/LARGE + INDEX
Works in any version, though longer.
=INDEX([B$2:M$2], MATCH(LARGE([B$2:M$2], COLUMNS($A:A)), [B$2:M$2], 0))
Parameters and Inputs
-
Core input is a horizontal range, e.g., [B2:M2]. Values can be numbers, dates, or text—SORT can handle all three, though mixed data types default to text sorting rules.
-
Optional sort_order determines direction. Ascending (1) ranks low to high; descending (-1) ranks high to low. In most ranking scenarios you will choose -1.
-
by_col must be TRUE (or 1) to force column-wise sorting; leaving this argument blank makes SORT behave in its default row-sorting mode.
-
For multiline sorting—each row sorted independently—you typically wrap SORT inside BYROW or use MAP/LAMBDA. Ensure each row’s source range is uniform in width.
-
Data preparation: remove blank cells inside the range because blanks might bubble to the front in ascending sorts. Coerce text numbers to numeric if mixing.
-
Edge cases: duplicated values maintain their original left-to-right position (stable sort). #N/A or error values propagate; trap them with IFERROR if needed.
Step-by-Step Examples
Example 1: Basic Scenario
Imagine a single row of quiz scores:
| B | C | D | E | F | G | H | |
|---|---|---|---|---|---|---|---|
| 2 | 78 | 92 | 85 | 66 | 90 | 73 | 88 |
Goal: Sort these scores descending across the columns.
- Select cell B4 (or any empty cell with at least 7 blank columns to the right).
- Enter:
=SORT([B2:H2], 1, -1, TRUE)
- Press Enter. Excel spills a sorted row: 92, 90, 88, 85, 78, 73, 66.
Why it works: array [B2:H2] is fed into SORT. sort_index is set to 1, but because by_col = TRUE, Excel ignores sort_index’s column pointer and sorts every column by its own value. -1 triggers descending order.
Variation: convert the scores to ascending by switching -1 to 1. Troubleshooting: if you see #SPILL!, check for filled cells in the output area. Empty them or move the formula.
Example 2: Real-World Application
Scenario: A grocery chain tracks monthly revenue (in thousands) for five stores. Data is horizontal:
| B | C | D | E | F | G | H | I | J | K | L | M | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2 | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec |
| 3 | 240 | 210 | 260 | 220 | 275 | 290 | 310 | 300 | 280 | 270 | 260 | 255 |
Management wants the months reordered per store so the highest revenue months appear first. Steps:
- Place the cursor in B5.
- Input:
=LET(
data, B3:M3,
sorted, SORT(data, 1, -1, TRUE),
CHOOSE({1}, sorted)
)
LET names the data once, improving legibility. The cell spills twelve values sorted descending. Copy the formula down for each additional store row; Excel will adjust references (unless you anchor using $). Business benefit: dashboards can link to the sorted row to instantly display the top three months, or create conditional formatting to highlight store-peak months.
Integration: Use INDEX(sorted, 1, SEQUENCE(1,3)) to fetch only the three largest months for a headline KPI table.
Performance: Because the data is only twelve columns, the model recalculates instantly even with 1000 store rows. For 30 000 columns (rare but possible in log files), wrap the formula in IFERROR to suppress invalid results and use range limiting.
Example 3: Advanced Technique
Scenario: You manage a talent database with 200 employees, each evaluated across thirteen competency areas stored horizontally. You want every row dynamically sorted so the highest competency appears first per employee, and you cannot upgrade all colleagues to Microsoft 365. The workbook must run in Excel 2010 onward.
Approach: SMALL/LARGE with INDEX, entered as a dynamic spilling formula via Office 365 for you but convertible to legacy CSE (Ctrl Shift Enter) for others.
-
Assume competencies live in columns C through O, row 5 down.
-
In P5 enter:
=INDEX($C5:$O5, MATCH(LARGE($C5:$O5, COLUMNS($P5:P5)), $C5:$O5, 0))
- Copy right across to AB5 to cover thirteen columns, then copy down 200 rows.
Logic: COLUMNS($P5:P5) generates 1 then 2 then 3 as you copy right, feeding LARGE with k. LARGE returns the kth largest value in the same row. MATCH locates that value’s position and INDEX retrieves it, effectively moving the largest to the front. Because Excel evaluates per cell, this solution is computationally heavier, but it bypasses the absence of SORT.
Edge cases: Duplicate scores return the first match; use additional criteria or tie-breakers if ties matter. Speed tips: restrict ranges to the exact used area, avoid entire-row references, and consider turning off automatic calculation while pasting large blocks.
Tips and Best Practices
- Reserve sufficient spill space. Dynamic arrays require consecutive free cells to the right; consider placing formulas in hidden helper sheets.
- Combine SORT with TAKE to grab the top N sorted values:
=TAKE(SORT([B2:M2], 1, -1, TRUE), ,3)quickly isolates leaders. - Use structured references in Excel Tables, e.g.,
=SORT(Table1[@January:Table1[@December]], 1, -1, TRUE)for readability and auto-expansion. - For dashboards, wrap results in TEXTJOIN to produce a comma-separated list of top values:
=TEXTJOIN(", ", TRUE, TAKE(sorted, ,5)). - Protect downstream formulas from errors by nesting IFERROR or LET to handle blanks and text gracefully.
- Document units and sorting rules in cell comments or a nearby legend so collaborators know whether values are ascending or descending.
Common Mistakes to Avoid
- Forgetting
by_col = TRUEand wondering why the row is unchanged. Double-check the fourth argument in SORT. - Spilling onto existing data. If #SPILL! appears, inspect the immediate right cells for hidden characters or formatting.
- Sorting a non-contiguous range. SORT expects one rectangular area; consolidate ranges first or build an array with CHOOSECOLS.
- Mixing text and numbers expecting numeric order. Coerce with
--valueor VALUE before sorting, or ensure consistent data types. - Pasting static values over formulas too early. If you hard-paste sorted results and data later updates, your report will become stale.
Alternative Methods
Below is a comparison of methods to sort values by columns:
| Method | Excel Versions | Dynamic? | Complexity | Performance | Pros | Cons |
|---|---|---|---|---|---|---|
| SORT (by_col = TRUE) | 365/2021 | Yes | Very low | Excellent | One formula, auto-updates | Not in older versions |
| TRANSPOSE + SORT | 365/2021 | Yes | Low | Very good | Works when you prefer classic row sort | Requires double transpose |
| INDEX/LARGE | 2007+ | Semi | Medium | Moderate | Backwards compatible | Longer formulas, ties need care |
| VBA Macro | 2007+ | Optional | High | Fast for huge sets | Opens automation possibilities | Requires code, security prompts |
| Power Query | 2010+ (with add-in) | Refreshable | Medium | Good for large tables | No formulas, ETL workflow | Needs manual refresh or VBA |
When you need maximum compatibility, choose INDEX/LARGE. For automated dashboards in modern Excel, SORT is king. For millions of values, Power Query’s column pivot and sort operations might outperform native formulas.
FAQ
When should I use this approach?
Use column-based sorting whenever your key comparison runs horizontally: monthly breakdowns, competency matrices, survey Likert scales, or regional splits that you wish to rank visually or programmatically.
Can this work across multiple sheets?
Yes. Prefix your ranges with sheet names: =SORT(Sheet1!B2:M2, 1, -1, TRUE). Ensure both sheets are open and within the same workbook; external links slow recalculation.
What are the limitations?
Dynamic arrays require contiguous spill space and are unavailable in Excel 2016 or earlier. SORT cannot handle non-rectangular areas directly. Error values propagate. Sorting text mixed with numbers follows lexicographic order, which might surprise users expecting numeric order.
How do I handle errors?
Wrap the formula: =IFERROR(SORT([B2:M2],1,-1,TRUE),"Check data"). Alternatively, clean data first: use CLEAN or SUBSTITUTE to remove stray spaces that generate #VALUE!.
Does this work in older Excel versions?
The dynamic SORT function is not present, but INDEX/LARGE formulas, helper rows, or VBA provide functional substitutes. See Alternative Methods.
What about performance with large datasets?
Dynamic arrays handle thousands of columns quickly but may lag beyond 50 000 cells. Use Power Query or VBA for tens of thousands of columns, or calculate once and convert to values. Turn off automatic recalculation while bulk-editing.
Conclusion
Being able to sort values across columns unlocks a wealth of analytical insights in dashboards, reports, and decision-support tools. Whether you leverage the sleek SORT function in Microsoft 365, fall back on INDEX/LARGE in legacy workbooks, or call on Power Query for heavy lifting, mastering horizontal sorting saves time and prevents costly misinterpretations. Continue exploring dynamic arrays, pairing SORT with FILTER, TAKE, or DROP to create responsive, professional spreadsheet solutions that impress stakeholders and accelerate your workflow.
Related Articles
How to Show the 10 Most Common Text Values in Excel
Learn multiple Excel methods to list the 10 most frequent text values—complete with step-by-step examples, business use cases, and expert tips.
How to Abbreviate Names Or Words in Excel
Learn multiple Excel methods to abbreviate names or words with step-by-step examples and practical applications.
How to Abbreviate State Names in Excel
Learn multiple Excel methods to abbreviate state names with step-by-step examples, professional tips, and real-world applications.