Sub topic 17
Cleaning and Reshaping Entered Data
Assume you can select ranges, enter formulas, and use basic copy-and-paste commands. This chapter uses a small imported contact list. The goal is to turn inconsistent text into reliable columns without losing the original data.
Inspect Before You Change
Data cleanup means correcting inconsistencies in entered or imported values. Reshaping means changing the arrangement of data, such as splitting one column into two.
Make a backup first. Right-click the sheet tab and choose Duplicate, or copy the original range to a new sheet named Raw data. Keep this copy unchanged so you can compare your results.
Look for:
- Extra spaces before or after names.
- Several spaces between words.
- Comma-separated values stored in one cell.
- Repeated rows.
- Numbers or dates stored as text.
This process helps you choose the correct cleanup operation:
Remove Unwanted Spaces
The TRIM function removes leading and trailing spaces and reduces repeated spaces between words. If the original value is in A2, enter this formula in another column:
=TRIM(A2)Fill the formula down. Check the results, then copy the cleaned column and use Edit > Paste special > Values only over the original column if you want to replace the formulas with plain text.
You can also select a range and choose Data > Data cleanup > Trim whitespace. This changes the selected cells directly, so use it only after preserving the raw data.
> callout warning > TRIM does not remove every invisible character. Imported web data can contain non-breaking spaces or other characters that look ordinary. If TRIM does not solve the problem, inspect the source or use a more specific cleanup formula.
Split Data into Columns
Suppose A2 contains:
Ada Lovelace,[email protected],LondonTo place each comma-separated part in its own column, select the values and choose Data > Split text to columns. Select Comma as the separator. Sheets writes the pieces into neighboring columns, so make sure those columns are empty.
For a formula-based result, use:
=SPLIT(A2,",")SPLIT returns multiple values across the row. It is useful when you want the original column to remain unchanged or when the cleanup should update automatically.
Remove Duplicate Rows
A duplicate row is a row repeated with the same identifying values. Select the full data range, including headers, then choose Data > Data cleanup > Remove duplicates. Tell Sheets whether the range has a header row, select the columns that define a duplicate, and review the number of rows removed.
Do not remove duplicates based on a single column unless that column must be unique. Two people may share a last name, and two orders may have the same date.
| Cleanup need | Suitable method |
|---|---|
| Extra spaces | Trim whitespace or `TRIM` |
| One field contains separated values | Split text to columns or `SPLIT` |
| Repeated records | Remove duplicates |
Verify the Cleaned Data
Check row counts before and after cleanup. Spot-check values against the raw sheet. Confirm that splitting did not overwrite existing data and that duplicate removal used the correct columns. After verification, format dates and numbers only if their underlying values are correctly recognized.
Exercise
Cells A2:A100 contain names with inconsistent spaces. Write a formula that cleans the value in A2, then explain how to replace the formulas with plain text.
Show answer
Use =TRIM(A2) and fill it down. Copy the results, then use Edit > Paste special > Values only to replace the original values without keeping formulas.