VBA & Macro Problems

Update the Same Data in Multiple Excel Workbooks with VBA

Steve KSteve K Nov 22, 2026 868 views

Question details

Update identical information across multiple Excel workbooks, even when the target data is in different cell locations.

Update the Same Data in Multiple Excel Workbooks with VBA
Product
Microsoft Excel
Device & OS
not provided
Scenario
A user needs to find and change the same information in many workbooks without manually editing each file.
Observed behavior
The desired result is for each selected workbook to be searched, updated, saved, and closed, with files needing review logged separately.
Before you start

Decide which files to include and how to identify the target data, such as an exact value, worksheet name, or label. Test the macro on copies in a separate folder, and close the target workbooks before running it.

Solution 1Recommended

Use VBA to Find and Replace a Value in Multiple Excel Workbooks

Use this example when every target is an exact text value and all matching nonformula cells in the selected folder should be updated.

The example searches all worksheets in each .xlsx file in one folder. It does not search subfolders, and it skips formula cells. Adapt the search logic if you need to update a cell next to a label or limit changes to a particular worksheet.

The example value must not contain Excel Find wildcard characters such as *, ?, or ~. It replaces every matching nonformula cell, so choose a value that uniquely identifies the intended data.

1
Create a macro workbook

In desktop Excel, create a workbook and save it as an Excel Macro-Enabled Workbook (.xlsm) using File > Save As.

2
Add the VBA procedure

Press Alt+F11, select Insert > Module, and paste the following code. Change OLD_TEXT and NEW_TEXT to the values you need: Option Explicit Sub UpdateWorkbooks() Const OLD_TEXT As String = "Old value" Const NEW_TEXT As String = "New value" Dim picker As FileDialog Dim folder As String, fileName As String Set picker = Application.FileDialog(msoFileDialogFolderPicker) If picker.Show <> -1 Then Exit Sub folder = picker.SelectedItems(1) & Application.PathSeparator fileName = Dir(folder & "*.xlsx") Do While fileName <> "" If Left$(fileName, 2) <> "~$" Then UpdateOneWorkbook folder & fileName, OLD_TEXT, NEW_TEXT End If fileName = Dir() Loop MsgBox "Finished. Open the Immediate window in the VBA editor to review the log." End Sub Sub UpdateOneWorkbook(ByVal path As String, ByVal oldText As String, ByVal newText As String) Dim wb As Workbook, ws As Worksheet Dim hit As Range, firstAddress As String Dim addresses As Collection, address As Variant Dim changed As Long On Error GoTo Failed Set wb = Workbooks.Open(Filename:=path, UpdateLinks:=0, ReadOnly:=False) If wb.ReadOnly Then Debug.Print path & " - opened read-only; skipped" wb.Close SaveChanges:=False Exit Sub End If For Each ws In wb.Worksheets Set addresses = New Collection Set hit = ws.UsedRange.Find(What:=oldText, LookIn:=xlValues, LookAt:=xlWhole, _ SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False) If Not hit Is Nothing Then firstAddress = hit.Address Do If Not hit.HasFormula Then addresses.Add hit.Address Set hit = ws.UsedRange.FindNext(hit) If hit Is Nothing Then Exit Do Loop While hit.Address <> firstAddress End If For Each address In addresses ws.Range(CStr(address)).Value = newText changed = changed + 1 Next address Next ws If changed > 0 Then wb.Save Debug.Print path & " - updated " & changed & " cell(s)" Else Debug.Print path & " - no matching nonformula cells found" End If wb.Close SaveChanges:=False Exit Sub Failed: Debug.Print path & " - error: " & Err.Description If Not wb Is Nothing Then wb.Close SaveChanges:=False End Sub

3
Run the macro

In the VBA editor, place the cursor inside UpdateWorkbooks and press F5. Select the folder containing the target .xlsx files.

4
Review the results

In the VBA editor, select View > Immediate Window to see updated cell counts, files without matches, read-only files, and errors. Open a few updated workbooks to verify the changes.

Use VBA to Find and Replace a Value in Multiple Excel Workbooks
Use trusted files: Only run macros and open workbooks from trusted sources. Protected sheets, permissions, or other workbook restrictions may prevent an update; review any errors in the Immediate window.
Free Microsoft Office alternative

Review and Edit Excel Workbooks with WPS Office

WPS Office is a free, lightweight Office alternative with a familiar interface for opening and editing spreadsheets. Its Excel format compatibility makes it easy to move existing files into WPS, though it does not resolve Excel-specific VBA issues.

Review and edit workbook data in WPS SpreadsheetsOpen and save Microsoft Excel .xlsx filesWork in a familiar spreadsheet interfaceUse a free, lightweight Office alternative
microsoft office alternative - wps office

Frequently Asked Questions

What if the data is in a different cell in each workbook?

Use VBA Find to search for a distinctive value or label instead of relying on a fixed cell address. If the value to change is next to a label, adapt the code to find that label and update the appropriate neighboring cell.

Will the example update files in subfolders?

No. The Dir(folder & "*.xlsx") line selects .xlsx files in the chosen folder only. The procedure must be extended to loop through subfolders if those files are also needed.

How can I see which workbooks were not updated?

After running the macro, open the VBA editor and select View > Immediate Window. The log lists files with no matching nonformula cells, files opened read-only, and errors.

Does the macro change formulas that display the old value?

No. The example searches displayed values but skips cells containing formulas. Review formulas separately if their results also need to change.

Can I update only one worksheet or selected files?

Yes. Modify the worksheet loop to target a named sheet, or replace the folder loop with a file picker or a list of specific file paths. Test the revised selection logic before processing all files.