Home › Guides › How to Sort a List Alphabetically (Online, Excel, Sheets)
Sorting a list alphabetically sounds trivial until the result looks wrong: “Item 10” lands before “Item 2”, capital letters jump to the top, or numbers sort as text. This guide shows how to sort a list alphabetically in a browser tool, in Excel and Google Sheets, in a text editor and on the command line, and explains why those surprises happen.
=SORT(A2:A100) in Excel 365.=SORT(A2:A100, 1, TRUE), or select the range and use Data → Sort range.When your list is in an email, a document or a web page, a browser tool is the quickest route:
Nothing is uploaded; the sorting happens in your browser, so private lists stay on your device.
“Alphabetical” is only one of several orders, and picking the wrong one causes most sorting problems. Here is the same list sorted three ways:
| Original | A → Z (alphabetical) | Natural |
|---|---|---|
| banana Item 10 apple Item 2 Cherry Item 1 | apple banana Cherry Item 1 Item 10 Item 2 | apple banana Cherry Item 1 Item 2 Item 10 |
Plain alphabetical order compares character by character, so “Item 10” comes before “Item 2” because the character 1 comes before 2. Natural sorting reads the digits as a whole number, which puts the items in the order a person expects. Use natural sorting for anything with numbers inside the text, such as file names, versions and product codes.
For a one-off sort, select the column and use Data → Sort A to Z. Excel offers to expand the selection to neighbouring columns so that rows stay together; choose that unless you really want to sort one column on its own.
If you want a live, sorted copy that updates when the source changes, Excel 365 and Excel 2021 have the SORT function:
=SORT(A2:A100)
Add a second argument of -1 to sort Z to A: =SORT(A2:A100, 1, -1). Excel’s sorting ignores letter case, so “apple” and “Apple” sort together.
=SORT(A2:A100, 1, TRUE)
The second argument is the column to sort by, and TRUE means ascending. Use FALSE for Z to A. To sort in place instead, select the range and choose Data → Sort range, then pick the column and direction.
| Editor | How |
|---|---|
| Notepad++ | Edit → Line Operations → Sort Lines Lexicographically Ascending (or Descending) |
| Visual Studio Code | Open the Command Palette (Ctrl+Shift+P) and run Sort Lines Ascending |
| Sublime Text | Edit → Sort Lines (shortcut F9) |
Notepad++ calls its alphabetical sort “lexicographic”, which compares character codes. That puts all capital letters before lowercase ones, so “Cherry” can appear before “apple”. If that is not what you want, sort with a tool that ignores case.
| Where | Command |
|---|---|
| Linux or macOS | sort list.txt. Add -f to ignore case, -n for numeric order, -r to reverse, -u to remove duplicates, and -V for natural “version” order on GNU systems. |
| PowerShell | Get-Content list.txt | Sort-Object. Add -Descending to reverse and -Unique to remove duplicates. |
Results from sort can depend on your system’s language and locale settings, which control how capitals and accents are ordered. If the order looks odd, that is usually the cause.
Paste the list into Sort Lines, one item per line, and choose A → Z. Copy the result or download it. The sorting runs in your browser and nothing is uploaded.
Select the column and choose Data, then Sort A to Z. In Excel 365 you can also use the formula =SORT(A2:A100) to get a live sorted copy.
Use =SORT(A2:A100, 1, TRUE) for a sorted copy, or select the range and choose Data, then Sort range.
Choose Edit, Line Operations, then Sort Lines Lexicographically Ascending. It sorts by character code, so capital letters come before lowercase ones.
Alphabetical sorting compares characters one at a time, and the character 1 comes before 2. Use numeric sorting for plain numbers, or natural sorting when numbers are part of the text.
Natural sort order reads runs of digits as whole numbers, so Item 2 comes before Item 10. It is the order most people expect for file names and version numbers.