Hi guys, i have a macro that i need to run on many excel files. All of the files are located in the same folder.
The macro, is a find/replace which uses data from a sheet ("sheet 2" in this case) and changes the data in "sheet 1".
All of the excel files have only one sheet and the sheet name is the same which the nam,e of the file. For example:
file name : 3 - 4
sheet name : 3 - 4
This is the macro that i use, big thanks to Leith Ross for writing it.
Sub MultiReplace()
Dim Cell As Range
Dim Dict As Object
Dim Rng As Range
Dim RngEnd As Range
Dim Wks As Worksheet
Set Dict = CreateObject("Scripting.Dictionary")
Set Wks = Worksheets("Sheet2")
Set Rng = Wks.Range("A1")
Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
If RngEnd.Row < Rng.Row Then Exit Sub Else Set Rng = Wks.Range(Rng, RngEnd)
For Each Cell In Rng
If Not IsEmpty(Cell) Then
If Not Dict.Exists(Cell.Value) Then Dict.Add Cell.Value, Cell.Offset(0, 1).Value
End If
Next Cell
Set Wks = Worksheets("Sheet1")
Set Rng = Wks.Range("A1:B1") 'include 2 columns to be searched
Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
If RngEnd.Row < Rng.Row Then Exit Sub Else Set Rng = Wks.Range(Rng, RngEnd)
For Each Cell In Rng
If Dict.Exists(Cell.Value) Then
Cell.Offset(0, 0) = Dict(Cell.Value) 'change value of the cell
End If
Next Cell
End Sub
Also the method should allow me to change which macro I want to run.
Thanks a lot for the help
Bookmarks