By the end of this lesson you will be able to
- Lay out a list as a tidy table with one heading row and one record per row.
- Sort a table by one or more columns without mixing up the rows.
- Filter a table to show only matching rows, then clear the filter.
- Create a drop-down list with data validation and explain how it prevents mistakes.
Many spreadsheets are not calculations at all but lists: a shop's stock, a club's members, a class register, a list of tasks. Once a list grows past a few rows you need to put it in order, find the rows that matter and keep the entries consistent. Sorting, filtering and validation do exactly that. They are also where beginners most often damage their own data, for example by sorting one column on its own, so this lesson spends time on doing it safely.
Start with a tidy table
Sorting and filtering only work well when the list is laid out as a proper table. The rules are simple: put one heading row at the top; give every column one kind of information; put one record per row, such as one item of stock; leave no blank rows or blank columns in the middle; and keep other things, such as notes or totals, away from the table (a blank row and column away, or on another sheet). Avoid merged cells in a list because sorting cannot handle them.
Our example is the stock list of a small, fictional shop, Wanjiru's Stationery. Each row is one product, with its category, how many are in stock and the level at which it should be reordered.
| Row | A | B | C | D |
|---|---|---|---|---|
| 1 | Item | Category | Quantity | Reorder level |
| 2 | Notebook | Paper | 40 | 20 |
| 3 | Pen | Writing | 8 | 25 |
| 4 | Ruler | Tools | 15 | 10 |
| 5 | Pencil | Writing | 60 | 30 |
| 6 | Stapler | Tools | 3 | 5 |
| 7 | Envelope | Paper | 90 | 40 |
- Marker 1: One heading row
- Marker 2: One record per row
- Marker 3: Numbers only in this column
Read this figure as text
A simulated spreadsheet containing a stock list with columns for item, category, quantity and reorder level.
A simulated spreadsheet with the stock list of a fictional shop. Row 1 is the heading row: Item, Category, Quantity and Reorder level in columns A to D. Row 2 is Notebook, Paper, 40, 20. Row 3 is Pen, Writing, 8, 25. Row 4 is Ruler, Tools, 15, 10. Row 5 is Pencil, Writing, 60, 30. Row 6 is Stapler, Tools, 3, 5. Row 7 is Envelope, Paper, 90, 40. The heading row is highlighted. Marker 1 points to the heading row. Marker 2 points to one complete record in row 3. Marker 3 points to the Quantity column, a column of numbers only.
Sorting without scrambling
Sorting puts the rows in an order: A to Z or Z to A for text, smallest to largest for numbers, oldest to newest for dates. The vital point is that sorting must move whole rows. If only one column moves, each item ends up beside the wrong quantity. Think of a row as a line of children holding hands: to rearrange them, you move the whole line, not one child.
Sort the stock list by quantity
Step 1: Select the table
Click any single cell inside the table, for example C3. Do not select just one column.
You should see: The spreadsheet can recognise the surrounding block of cells as the table.
Step 2: Open the Sort window
Open the Data menu and choose Sort... (Calc), or open the Data tab and choose Sort (Excel).
You should see: A Sort dialog opens. In Calc, check the Options tab: the box Range contains column labels should be ticked. In Excel, My data has headers should be ticked.
Step 3: Choose the sort key
Under Sort key 1 (Excel: Sort by) choose Quantity, and choose Ascending.
You should see: The column names from your heading row appear in the list, not Column A, Column B.
Step 4: Apply the sort
Click OK.
You should see: The rows are in order from smallest quantity to largest: Stapler 3, Pen 8, Ruler 15, Notebook 40 and so on. Each item still has its own quantity and reorder level.
To sort by two columns, add a second key: sort by Category first, then by Item within each category. Calc has a Then by section on the same tab and Excel has Add Level. For a quick sort you can also click a cell in a column and press the Sort Ascending or Sort Descending button on the toolbar. This works well when the table is tidy and has a heading row.
- Stapler: 3
- Pen: 8
- Ruler: 15
- Notebook: 40
Rows stay together: correct
- Notebook: 3
- Pen: 8
- Ruler: 15
- Stapler: 40
Quantities mixed up: damaged
Read this figure as text
A comparison of a correct sort that keeps each item with its quantity and a wrong sort that mixes them up.
Two columns compare outcomes. The left column, Sort the whole table, shows Stapler 3, Pen 8, Ruler 15, Notebook 40: the items and quantities stay together, and the verdict is correct. The right column, Sort one column only, shows Notebook 3, Pen 8, Ruler 15, Stapler 40 after only the quantity column was sorted: each quantity now belongs to the wrong item, and the verdict is the data is damaged. The safe habit is to click inside the table and let the program select the whole block, and to check the result straight away.
Filtering: showing only what you need
Filtering hides the rows that do not match your wish, without deleting them. The rows that remain are the answer to a question such as "Which items are in the Writing category?" The hidden rows are still there, and the row numbers on the left skip the missing ones, which is your clue that a filter is on. Calc calls this an AutoFilter; Excel calls it a Filter.
Filter for one category
Step 1: Turn on the filter
Click inside the table. Press Ctrl+Shift+L, or choose Data, then AutoFilter (Calc) or Filter (Excel).
You should see: Small drop-down arrows appear on each heading cell.
Step 2: Choose a category
Click the arrow in the Category heading. Untick everything except Writing (in Calc you may first untick Select all, in Excel untick Select All).
You should see: The list shows the values that exist in the column: Paper, Tools, Writing.
Step 3: Apply the filter
Click OK.
You should see: Only Pen and Pencil remain. The row numbers on the left show a gap, and the arrow in the heading changes to show that a filter is active.
Step 4: Clear the filter
To show everything again, open the same drop-down and tick all values again, or choose Data, then More Filters, Reset Filter (Calc) or Clear (Excel).
You should see: All six rows are back and the row numbers run without gaps.
A column of numbers offers number filters too, such as Standard Filter in Calc or Number Filters in Excel. You can choose rules like "Quantity less than 10". Combine the idea with a formula and you can ask more complex questions, for instance a column that says =IF(C2<D2,"Reorder","OK") which flags rows where the stock has fallen below the reorder level. Then filter that column for Reorder.
Data validation: stopping mistakes at the door
Data validation sets rules for what may be typed into a cell. It is the reason online forms show a drop-down list for the country instead of letting you type anything. In a stock list, if people type "Writing", "writing", "Writting" and "Pens", filtering and sorting no longer work properly, because the spreadsheet sees four different categories. A drop-down list with only the allowed values removes the problem.
Criteria | Input Help | Error Alert
Allow: List
Entries: Paper, Tools, Writing
[x] Show selection list
- Marker 1: Allow: choose List
- Marker 2: The only values allowed
- Marker 3: Apply the rule
Read this figure as text
A simulated dialog titled Validity with the Allow setting on List and the entries Paper, Tools and Writing.
A simulated dialog window titled Validity (Calc) or Data Validation (Excel). It has three tabs: Criteria, Input Help and Error Alert. On the Criteria tab, Allow is set to List. The Entries box contains three lines: Paper, Tools, Writing. Below it a ticked box reads Show selection list (Calc) or In-cell dropdown (Excel). Two buttons: OK and Cancel. Marker 1 points at the Allow setting. Marker 2 points at the list of allowed entries. Marker 3 points at the OK button that applies the rule to the selected cells.
Add a category drop-down
Step 1: Select the cells
Select the empty cells where categories will be typed, for example B2:B20.
You should see: The cells are highlighted and the Name Box shows B2:B20.
Step 2: Open data validation
Choose Data, then Validity... (Calc), or Data, then Data Validation (Excel).
You should see: The dialog opens.
Step 3: Create the list
In the Allow list choose List. In Entries type
Paper,ToolsandWriting, one per line (Calc). In Excel type them in the Source box separated by commas:Paper,Tools,Writing.You should see: The three allowed values are shown.
Step 4: Add an error message
Make sure the box for the selection list (Calc) or in-cell dropdown (Excel) is ticked. Open the Error Alert tab and tick Show error message when invalid values are entered, with the action Stop, and write a short message such as
Choose Paper, Tools or Writing.You should see: The message is shown whenever someone types something else.
Step 5: Apply and test
Click OK. Click a cell in B2:B20.
You should see: A small arrow appears. Click it to choose a category. Typing Pens is refused with your message.
Validation can also limit numbers. Choose Whole Numbers for the Quantity column and set a minimum of 0 so that nobody records minus five pens. Choose Date to allow only dates, or Text length to limit codes to a certain size. The rule applies to what is typed in future, and values already in the cells are not checked automatically. Pasting can also bypass the rule, so it is a guard, not a lock.
Common mistakes
✖ Instead of: Sorting a single column on its own.
✔ Do this: Click inside the table so that the whole block is sorted together. Save a copy first.
✖ Instead of: Leaving blank rows or merged cells inside the list.
✔ Do this: Keep one tidy block, with one heading row and no gaps.
✖ Instead of: Forgetting a filter is on and thinking rows have been lost.
✔ Do this: Look for the arrows in the headings and gaps in row numbers. Clear the filter to see everything.
✖ Instead of: Typing categories freehand, with different spellings.
✔ Do this: Use a validation drop-down list so that each category is spelt one way.
If something goes wrong
- The heading row got sorted into the middle of the data.
- Press Ctrl+Z. Open Sort again and, in Options (Calc) or the sort window (Excel), tick that the range contains column labels, then sort again.
- The numbers sort as 1, 10, 2, 20, 3.
- They are stored as text. Remove stray spaces or apostrophes, or set the column to a number format and retype the values. Left-aligned numbers are the clue.
- The filter shows no list of values, or misses new rows.
- The filter range may not include them. Turn the filter off and on again with a cell inside the table selected, with no blank rows in the table.
- The drop-down arrow does not appear.
- Open Data validation again for the cells and tick the box for the in-cell list (Show selection list in Calc, In-cell dropdown in Excel). Check that you selected the right cells.
Key terms
- sorting
- Sorting puts the rows of a list in order, such as A to Z or smallest to largest.
- filtering
- Filtering hides the rows of a list that do not match your condition.
- data validation
- Data validation sets rules for what can be typed into a cell, such as a list of allowed values.
Practise it for real
Reading is not the same as being able to do it. Complete these on your own computer, then tick only what you have actually done. These ticks are your own honest record: nothing checks them for you.
Build, sort and filter a stock list
Create a stock list with the headings Item, Category, Quantity and Reorder level and at least ten fictional products in three categories. Save a copy first. Sort by Category, then by Item. Sort by Quantity from smallest to largest. Turn on the AutoFilter and show only one category, then only items with a quantity under 10, then clear the filter. Finally, add a drop-down list to the Category column.
Challenge: flag items to reorder
In a fifth column called Status, write a formula that shows Reorder when Quantity is below Reorder level and OK otherwise, and fill it down. Filter the Status column to show only Reorder. Then add validation to the Quantity column that refuses negative numbers and test it by typing -3.
Knowledge check
7 questions. You need 80% to pass. Mistakes here are part of learning, and you can retry as often as you like.
Summary
- A tidy table has one heading row, one record per row and no gaps.
- Sorting moves whole rows. Click inside the table, save a copy first, and check the result.
- A filter hides rows without deleting them. Clear it to see everything again.
- Data validation drop-down lists keep entries consistent so sorting and filtering stay reliable.
- Validation guards typing but does not lock the cell against pasting.
Checklist: can you do these?
Marking a lesson as read does not prove you can do it. Skills count as demonstrated when you pass the quiz (not yet) and complete the practical tasks (not yet).
Related lessons
References and further reading
Official sources for details that can change between versions.
- LibreOffice Calc Guide (The Document Foundation)
- LibreOffice Help (The Document Foundation)
- Excel help and learning (Microsoft)