• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Find and Replace multiple File in one folder

minhys1

New Member
I have 2 excel files (File 1 and File 2), including 5 Sheets. The path address of the two files is D: \ TANG ANH MINH \ PHAN MEM \ EXCEL \ Find Replace Multiple File
From the 3rd newly created excel file, I want to search and replace the values in the two excel files above, in all the cells of the 5 Sheets respectively as follows:
RED> YELLOW
BLUE> GREEN
BROWN> SHADOW
BLACK> WHITE
How to use Excel VBA for this purpose?

 
I found this code, but it works just fine with an excel file. I need to replace multiple excel files in one folder, and replace many words at the same time

>>> use code - tags <<<
Code:
Sub FindReplaceAll ()
Dim sht As Worksheet
Dim fnd As Variant
Dim rplc As Variant
fnd = "April"
rplc = "May"
For Each sht In ActiveWorkbook.Worksheets
sht.Cells.Replace what: = fnd, Replacement: = rplc, _
LookAt: = xlPart, SearchOrder: = xlByRows, MatchCase: = False, _
SearchFormat: = False, ReplaceFormat: = False
Next sht
End Sub
 
Last edited by a moderator:
This code has replaced many words in many sheets at once (requires opening File 1 or File 2, then running the code). Now just need to expand the functionality on multiple excel files in one folder to complete

>>> use code - tags <<<
Code:
Sub Multi_FindReplace()
Dim sht As Worksheet
Dim fndList As Variant
Dim rplcList As Variant
Dim x As Long
fndList = Array("RED", "BLUE", "BLACK","BROWN")
rplcList = Array("YELLOW", "GREEN", "WHITE","SHADOW")
'Loop through each item in Array lists
For x = LBound(fndList) To UBound(fndList)
'Loop through each worksheet in ActiveWorkbook
For Each sht In ActiveWorkbook.Worksheets
sht.Cells.Replace What:=fndList(x), Replacement:=rplcList(x), _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next sht
Next x
End Sub
 
Last edited by a moderator:
Back
Top