Find and Replace Across Excel Workbooks
Operator: Abdulla Al Fahad. How tools are built and checked
A supplier changes its name, a product code is retired, or a department is renamed, and the old wording sits in forty workbooks. Excel's own Find and Replace can work across the sheets of one open workbook, but not across a folder of closed files, so the usual answer is to open each file, run the replacement, save and close, and hope none was skipped.
This tool takes up to 50 .xlsx files and a list of find and replace pairs, and runs every pair over the text cells of every chosen sheet. Before you download anything it shows how many cells would change in each workbook and sheet, with the first hundred edits side by side. The ZIP you then download holds only the workbooks that changed, under their original names, together with a CSV log of every edited cell. Cell styles, number formats and column widths normally carry over, because the exceljs library edits each workbook's cells rather than rebuilding the file from bare values, though parts that exceljs does not model can still be lost, as the warnings described below explain.
Key features
- Up to 200 find and replace pairs, typed in rows or pasted as CSV or as two columns copied from a spreadsheet
- Match case, whole cell, whole word and regular-expression options
- Formula cells skipped by default, with an option to edit formula text
- All sheets, or only the sheet names you tick
- Counts of changed cells and replacements per workbook and sheet before download
- Formatting, number formats, column widths, merged cells and notes kept in the changed copies
- A ZIP of only the changed workbooks, names unchanged, plus change-log.csv
- Warnings for workbooks whose charts, pivot tables or other parts may not survive the rewrite
Refused workbooks, risky parts and the change log
A run takes between 1 and 50 .xlsx workbooks. No single file may pass 25 MB, and together they may not pass 200 MB, because after a preview the tab keeps every changed copy so the ZIP can be built from them. Macro-enabled .xlsm files are refused, and so is a workbook that contains macros under an .xlsx name, because rewriting either would strip the VBA project. A workbook in the older .xls format, or one locked with an opening password, is refused along with instructions for saving a plain .xlsx copy.
When a file is added, its parts are listed without opening the cells. A workbook that holds charts, chart sheets, pivot tables and their caches, slicers or timelines, links to other workbooks, threaded comments, form controls, data connections, or shapes and text boxes gets a warning under its name, because exceljs does not model those parts and a rewritten copy may lose them.
The change log is comma-separated UTF-8 text, opened by a byte-order mark, with five columns: File, Sheet, Cell, Before and After. Formula edits are logged with their leading equals sign. Logged text whose first character is =, +, -, @, a tab or a carriage return gets an apostrophe added in front, so a spreadsheet opening the log shows it as text rather than treating it as a formula.
How it works
Each pair becomes one search pattern. In plain mode the find text is matched literally; in regular-expression mode it is used as a JavaScript pattern. Pairs then run from top to bottom over each cell, and each pair works on the text the earlier pairs left behind, so a list that turns A into B and then B into C turns A into C.
Whole cell only accepts a match that covers the entire cell, spaces included. Whole word rejects a match whose first or last character is a letter or digit that touches another letter or digit outside it. The check works for accented and non-Latin letters too, so café is not matched inside cafés, and a find text that starts with a space, such as " Ltd", still matches after a word.
The cells searched are plain text cells, rich text cells and the shown text of hyperlink cells. Numbers, dates, TRUE and FALSE, and error values are never changed, even when their digits match; the preview reports how many number cells had matching digits so a zero result is not a mystery. Header cells of Excel tables are left alone and listed, because a table also stores its column names separately and the two would stop agreeing.
In a rich text cell each run keeps its own font. If a match crosses two runs with different formatting, for instance a bold AC followed by plain ME, the cell is not changed and is listed for you to edit by hand. A cell whose text is replaced with nothing becomes empty but keeps its formatting.
With Include formulas on, the formula text itself is searched and edited, its saved result is removed, and the workbook is flagged so Excel recalculates every formula when it opens. A formula that was filled down is stored once and shared by the cells below it. Such a group is changed only when editing the stored formula gives every cell the same text it would get if edited alone; otherwise the whole group is left as it was and listed. Cells inside the range of an array formula only hold its last results and are skipped.
Common use cases
- Updating a supplier or client name after a rebrand across a year of invoice registers
- Replacing retired product codes in every regional price list at once
- Renaming a department in a folder of staffing and budget workbooks
- Correcting a misspelt place name that was copied into dozens of project trackers
- Pointing formulas at a renamed sheet in many workbooks with Include formulas on
How to use this tool
- Add the .xlsx workbooks. Each shows its sheet count, a refusal reason, or a warning about parts that may be lost.
- Type the first pair, add more rows as needed, or paste a list under Paste a list of pairs.
- Set the matching options and choose whether formulas are included and which sheets are searched.
- Press Preview changes and read the counts per workbook and sheet, the notes below them and the sample of edits.
- If the numbers look wrong, adjust a pair or an option and preview again; nothing is saved until you download.
- Download the ZIP, or the single changed workbook when only one changed, and keep change-log.csv with it.
Example
Two price lists and three pairs (match case and whole word on)
Pairs:
1. Brightwell Ltd -> Brightwell Supplies Limited
2. Ltd -> Limited
3. SKU-044 -> SKU-144
q3-prices.xlsx, sheet Prices
A2 Brightwell Ltd C2 Ships via Hargreaves Ltd
C3 Ltda branch, Porto
B4 SKU-044
q4-prices.xlsx: no matchesPreview and change-log.csv
3 cells changed in 1 of 2 workbooks (3 replacements)
File,Sheet,Cell,Before,After
q3-prices.xlsx,Prices,A2,Brightwell Ltd,Brightwell Supplies Limited
q3-prices.xlsx,Prices,C2,Ships via Hargreaves Ltd,Ships via Hargreaves Limited
q3-prices.xlsx,Prices,B4,SKU-044,SKU-144
C3 is untouched: whole word stops Ltd from matching inside Ltda.
The ZIP holds q3-prices.xlsx and change-log.csv.Tips for best results
- Put the longest, most specific pairs first. In the example, Brightwell Ltd is handled before the general Ltd rule, otherwise the general rule would change it first and pair 1 would never match.
- Turn on Whole word for short find texts such as Ltd or UK, or they will also change Ltda or UKG.
- Run with Include formulas off first. The preview tells you how many formula cells contain the text, so you can decide whether editing formulas is needed at all.
- In regular-expression mode, use $1 to keep part of the match, as in ^INV-(\d+)$ replaced with Invoice $1.
- Keep change-log.csv with the changed files; it is the only record of what each cell said before.
Common pitfalls
Pairs are chained. If one pair changes North to South and a later one changes South to West, every North ends up as West. Order the list, or split it into two runs.
The replacement is written exactly as typed. Replacing acme with Apex while Match case is off turns ACME, Acme and acme all into Apex; capitals are not carried over from the old text.
With Include formulas on, a find text that looks like a cell reference, such as B2, can rewrite references and change what the formula calculates. Filled-down groups where this would happen are left unchanged and listed, but single formulas are edited as asked.
Sheet protection does not stop the edit. A locked cell on a protected sheet is changed like any other, which Excel's own Find and Replace would refuse to do.
exceljs does not keep every part of a workbook. A formula cell that also carries a hyperlink comes back as its value, and charts, pivot tables, slicers, shapes and form controls may be dropped from a changed copy. Open each warned file before replacing the original.
A pattern with nested repetition, such as (a+)+, can take a very long time on long cells and make the tab stop responding. Simplify the pattern if a preview seems stuck.
Common errors and how to fix them
- "... is a macro-enabled workbook" or "... contains macros even though its name ends in .xlsx"
- Saving through exceljs would remove the VBA project, so the file is refused instead. Make the change in Excel for that file, or work on a copy saved without macros if they are not needed.
- "Pair 2: ... is not a valid regular expression"
- The pattern has a syntax error, such as an unclosed bracket, and the message quotes the browser's reason. Fix it, or turn off Regular expression to search for the characters exactly as typed.
- "... can match empty text"
- A pattern such as ACME| or x* also matches nothing at all, which would insert the replacement between characters. Rewrite it so it always needs at least one character.
- "More than 200,000 cells would change in this run."
- The find text is probably too general. Turn on Whole word or Whole cell, make the text longer, or run fewer workbooks at a time.
Best practices
- Preview with a single pair first to confirm the count matches what you expect, then add the rest.
- Check the notes under the preview table for skipped cells before downloading.
- Open one changed workbook from each warning group and compare it with its original.
- Keep the originals until the changed copies have been checked; the tool never modifies them.
What is not searched
Only cell contents are searched. Sheet names, comments and notes, headers and footers, text boxes and shapes, chart titles, data-validation lists, defined names and the text inside conditional formatting rules are left alone. Hyperlink cells get their shown text changed but keep their link address, so a link labelled with an old domain still points at it.
Merged ranges store their value in the top-left cell only, so a merged label is counted and changed once, at that address.
Where the work happens
Each workbook is read from your disk into this tab, edited there by exceljs and packed by JSZip; no file or cell text is sent to a server. After a preview, the tab keeps the changed copies as blobs and the change log as text until you edit a pair, an option or the file list, or close the page. Each download link is an object URL that the tab revokes a second after the save begins.
Frequently asked questions
Are my original workbooks changed?
No. The tool reads them and writes new copies, so the files on your computer stay exactly as they were until you replace them yourself.
Why is a workbook missing from the ZIP?
The ZIP only holds workbooks in which at least one cell changed. The preview table lists every workbook, with "No matches" or an error for the ones left out.
Can I replace text in numbers?
No. Numbers, dates and TRUE/FALSE values are left alone, so a search for 2024 never alters the number 2024 or a date in that year. It does change 2024 inside a text cell such as FY2024.
What happens to formulas when Include formulas is on?
The formula text is edited and its saved result is removed, and the workbook is marked so Excel recalculates every formula when it opens. A viewer that does not recalculate may show those cells empty until the file has been opened and saved in Excel.