Sub topic 11
Replacing formulas with cleaned values
This chapter assumes you can enter and copy formulas, understand relative references such as A2, and know that Excel treats text and numbers differently. You should also have built a helper column with =PROPER(TRIM(CLEAN(A2))), or a version that uses SUBSTITUTE, from the earlier chapters.
Why the formulas have to go
A helper column gives you clean text, but each cell still holds a formula that points at the original messy cell. That causes three problems.
- The cleaned column depends on the dirty one. If you delete column A, the formulas in column B show
#REF!. - Other tools see formulas, not data. Copying the column into another program, a mail merge, or a database import can bring along formulas or error codes instead of text.
- Recalculation can change results. If someone edits the original cell, the cleaned cell changes too. Sometimes you want that. For a one-time cleanup you usually don't.
The fix is to replace each formula with the value it currently shows. Excel calls this Paste Special, Values. After it runs, the cell holds plain text and has no link to the source.
Pasting values step by step
Suppose column A holds raw names from row 2 down, and column B holds =PROPER(TRIM(CLEAN(A2))) filled down to row 500.
- Select the formula cells, B2:B500. You can click B2, then press Ctrl+Shift+Down Arrow to extend the selection to the last filled cell.
- Copy them with Ctrl+C. A moving border appears around the selection.
- Keep the same cells selected. Do not click elsewhere.
- Open Paste Special. On Windows press Ctrl+Alt+V. On Mac press Control+Command+V. You can also use Home, then the Paste drop-down, then Paste Values (the clipboard icon marked 123).
- In the dialog, choose Values and press Enter.
- Press Esc to clear the moving border.
Pasting over the same cells is the point. The formulas are overwritten by their own results, so column B now holds text and nothing else.
Paste in place or paste elsewhere
| Choice | When to use it | Trade-off |
|---|---|---|
| Paste values over the helper column | You want to keep column A as a reference and delete it later | Column B has the final text, and A and B stay side by side until you delete one |
| Paste values over the original column | You want the cleaned data in the original location | You lose the raw text, so make a backup first |
To paste over the original, copy B2:B500, select A2:A500, and use Paste Values there. Then delete column B, which only held the temporary formulas. Other formulas, charts, or named ranges may refer to column A, and this approach keeps them working because column A never moves.
Check the result before you delete anything
Two mistakes are easy to make: pasting only part of the range, and pasting values before the formulas were correct. Run a few checks first.
To count how many cells in the range still contain formulas, use ISFORMULA:
=SUMPRODUCT(--ISFORMULA(B2:B500))After a full paste, this returns 0. You can put it in any empty cell outside the data, then delete it.
To see how many rows the cleaning actually changed, compare the raw and cleaned columns with EXACT, which is case-sensitive:
=SUMPRODUCT(--NOT(EXACT(A2:A500,B2:B500)))A result of 0 on a column you expected to need cleaning is a warning sign. The formulas may not be doing what you think.
To confirm that no extra spaces remain, run this on the pasted values:
=SUMPRODUCT(--(LEN(B2:B500)<>LEN(TRIM(B2:B500))))It returns 0 when every cell is already trimmed. If it returns something higher, look for non-breaking spaces. Use =UNICODE(RIGHT(B2,1)) on one of the failing cells. A result of 160 means you need SUBSTITUTE(B2,CHAR(160)," ") before trimming.
What Paste Values does not carry over
Paste Values copies results only. Several things behave differently from a normal paste.
- Formatting stays with the destination. Fonts, fills, and borders from the source are not copied. If you paste to a new location, the cells take on whatever format is already there.
- Number formats of the destination apply. If the destination cells are formatted as Text, pasted values stay text. If they are General, Excel may reinterpret entries that look like numbers or dates. The next chapter covers numbers that stay as text.
- Empty-string results become empty text, not truly blank cells. A formula such as
=TRIM(A2)on a blank A2 returns"". Pasting that as a value can leave a cell that looks blank but is not.ISBLANKreturns FALSE for it, andCOUNTAcounts it. If this matters, use Find & Replace or Go To Special to clear them, or check with=LEN(B2)=0. - Data validation, comments, and conditional formats are not pasted. Only the value moves.
Edge cases
Filtered data
Copying a filtered range copies only the visible rows, which is usually what you want. Pasting into a filtered range is riskier. Excel pastes into every row in the selection, including hidden ones, in some cases, and may not line up as you expect. The safe approach is to clear the filter, paste values over the full range, then reapply the filter.
Excel tables
In a table, a formula column can auto-fill new rows. After you paste values, that column becomes static, so new rows will not be cleaned for you. If you need ongoing cleanup, keep the formula column and copy cleaned data out to a separate sheet when needed.
Spilled formulas
If you use a dynamic array formula such as =TRIM(A2:A500) entered in one cell, it fills the cells below it. Select the whole spill range, not only the first cell, then copy and paste values. If you copy only the top cell, you get just one value.
=PROPER(TRIM(CLEAN(A2:A500)))In versions of Excel that support dynamic arrays, this one formula cleans the whole column. Paste Values over the spill area replaces the spill with static text, and the formula is gone.
Large ranges
Pasting values on tens of thousands of rows is fast. The slow part is the formula column before the paste. If recalculation is lagging, set Formulas, then Calculation Options, then Manual, paste your values, and switch back to Automatic.
When not to paste values
Keeping the formulas is sometimes the better choice.
- The source data is refreshed regularly, for example a weekly export pasted into column A. A live helper column cleans every refresh without extra work.
- You want an audit trail showing exactly which transformations were applied.
- Other people will review the logic and need to see the formula.
In those cases, keep column A as an input sheet and use the cleaned column as the output. Paste Values is for the case where the cleaning is finished and the cleaned text is now the data.
A complete example
You have a list of customer names in A2:A200 imported from a web form. Some have trailing non-breaking spaces and line breaks.
- In B2, enter a formula that handles both:
=PROPER(TRIM(CLEAN(SUBSTITUTE(SUBSTITUTE(A2,CHAR(160)," "),CHAR(10)," "))))The inner SUBSTITUTE calls convert non-breaking spaces and line feeds to ordinary spaces. CLEAN then removes any remaining control characters, TRIM collapses the spaces, and PROPER fixes capitalization.
- Fill the formula down to B200.
- Scan the results for names that
PROPERhandled badly, such asMcDonaldorO'Sullivan. Fix the formula or plan to correct these cells by hand after the paste. - Copy B2:B200, then Paste Values over B2:B200.
- Run
=SUMPRODUCT(--ISFORMULA(B2:B200))and confirm it returns 0. - Run the
LENversusTRIMcheck above and confirm it returns 0. - Delete column A, or move it to a sheet named Raw so you keep the original.
Do the manual fixes for step 3 after step 4. Once the cells are values, you can type over them freely without breaking any formula.
Exercise
Your helper column B contains =TRIM(A2) down to row 100. You copy B2:B100, click A2, and use Paste Values. Then you delete column B. What do you end up with in column A, and why is nothing broken?
Show answer
Column A holds the trimmed text as plain values. The formulas were never pasted, only their results, so nothing refers to column B anymore. Deleting B causes no #REF! errors. The raw, untrimmed text in A is permanently gone, which is why you should keep a backup copy first.
Exercise
After pasting values over B2:B500, you run =SUMPRODUCT(--(LEN(B2:B500)<>LEN(TRIM(B2:B500)))) and get 14. Which character is the most likely cause, and how would you confirm it on one cell?
Show answer
Non-breaking spaces (character 160), which TRIM does not remove. To confirm, check a failing cell with =UNICODE(RIGHT(B2,1)) (or look at the first character with LEFT). A result of 160 confirms it. The fix is to run =SUBSTITUTE(B2,CHAR(160)," ") before TRIM, then paste values again.
Exercise
A formula =TRIM(A5) returns an empty string because A5 is blank. After Paste Values, ISBLANK on that cell returns FALSE. Why, and how can you test that the cell is effectively empty?
Show answer
Paste Values keeps the empty text string "" as the cell's content, so the cell is not truly blank. Test it with =LEN(B5)=0, which returns TRUE for an empty-text cell. To make the cell truly blank, select it and press Delete.