Replace VBA from main file for all other excel files

HoaNguyen

New Member
Joined
May 26, 2023
Messages
3
Office Version
  1. 2019
Platform
  1. Windows
  2. MacOS
  3. Web
Sub MF_Replace()
Dim i As Long, Clls As Range, Ws As String, Sh As Worksheet
Application.ScreenUpdating = False
With Application.FileDialog(1)
.AllowMultiSelect = True: .Show
For i = 1 To .SelectedItems.Count
Ws = Replace(.SelectedItems(i), .InitialFileName, "")
If ThisWorkbook.Name <> Ws Then
Workbooks.Open .SelectedItems(i)
For Each Clls In ThisWorkbook.ActiveSheet.[A1].CurrentRegion.Resize(, 1)
Windows(Ws).Activate
For Each Sh In ActiveWorkbook.Worksheets
Sh.Cells.Replace Clls, Clls.Offset(, 1), LookAt:=xlWhole
Next Sh
Next Clls
Windows(Ws).Close True
End If
Next i
End With
Application.ScreenUpdating = True
MsgBox "Done"
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I have a table of data: Column A is the data to be replaced, Column B is the data to be replaced. Now I want to run the Data table replacing the words in Column A with Column B for all the Excel copies I select. In the above Code, I can only replace 1 time, and cannot replace a number of characters. Hope you guys can help me
 
Upvote 0

Forum statistics

Threads
1,215,751
Messages
6,126,671
Members
449,326
Latest member
asp123

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top