Sub topic 15
Editing many cells with Find and Replace
This chapter assumes you can select cells, type and commit entries, and enter edit mode with F2. Find and Replace changes many cells in one step, so you don't have to edit each cell by hand.
Opening the dialog
Press Ctrl+H to open the Replace tab. Press Ctrl+F to open the Find tab. Both tabs use the same dialog. Click Options >> to see the full set of settings.
The search covers the current worksheet by default. If you select a range first, the search covers only that range. Selecting a range before you replace is the simplest way to avoid changing cells you did not intend to touch.
The core settings
| Setting | What it does |
|---|---|
| Find what | The text or number to look for |
| Replace with | The text that takes its place. Leave it empty to delete the match |
| Within | Search the current Sheet or the whole Workbook |
| Look in | Search Formulas, Values, or Comments |
| Match case | Treats "North" and "north" as different |
| Match entire cell contents | Matches only cells that contain exactly the search text |
Wildcards work in Find what. ? matches any single character and * matches any run of characters. To search for a literal ? or *, put a tilde before it, as in ~*.
A worked example
Suppose column A holds product codes such as SKU-1001, SKU-1002, and SKU-1003. The supplier changes the prefix to ITM-.
- Select the cells in column A.
- Press Ctrl+H.
- In Find what, type
SKU-. - In Replace with, type
ITM-. - Click Replace All.
Excel reports how many replacements it made. Each cell now holds ITM-1001, ITM-1002, and so on.
Replacing one match at a time
Find Next moves to the next match without changing anything. Replace changes the current match and moves on. Find All lists every match with its address, and you can click an entry in the list to jump to that cell. Use these when you are unsure how many cells will change.
Common errors
- Matching too much. Replacing
10with20also turns105into205. Turn on Match entire cell contents when you want only cells that equal10. - Searching the wrong layer. With Look in set to Formulas, Excel searches the formula text. With Values, it searches what is displayed. A cell showing
15because of=A1+B1matches15only under Values. Chapter material on stored versus displayed values applies here. - Leftover settings. Excel remembers options such as Match case between searches in the same session. A search that finds nothing is often caused by a setting you chose earlier.
- Replacing in formulas. Replace All can alter cell references inside formulas when Look in is Formulas. Review the matches with Find All first.
Replacing formats
Click Format... beside either box to search for, or apply, a format such as bold or a fill color. This lets you change, for example, every red-filled cell to yellow without changing its contents.
Exercise
A column contains the values 5, 15, and 50. You replace 5 with 9 using Replace All and no other settings. What does the column contain afterward, and which setting would have limited the change to the first cell?
Show answer
The column contains 9, 19, and 90, because every occurrence of the digit 5 inside a cell is replaced. Turning on Match entire cell contents would change only the cell equal to 5, leaving 15 and 50 alone.