Macro to Search and Replace

  • Thread starter Thread starter Excel_Rookie
  • Start date Start date
E

Excel_Rookie

I'm wondering if its possible to have a macro that will find cells wit
specified text and replace it with other specified text.

I have a lot of files that have these same cells that need to b
modified and looking for a way to save time.

Thanks
 
Hey Rookie,

If the files are all in the same folder, and are only one sheet long, then
something like this will do it:

Sub RunMacroOnAllFilesInFolder()
With Application.FileSearch
.NewSearch
'Change the folder name
.LookIn = "C:\Excel"
.FileType = msoFileTypeExcelWorkbooks
If .Execute > 0 Then
For i = 1 To .FoundFiles.Count
Workbooks.Open .FoundFiles(i)
'Put your recurring macro code here
Cells.Replace What:="FindThis", _
Replacement:="Replacement", _
LookAt:=xlPart
ActiveWorkbook.Close True
Next i
End If
End With
End Sub

HTH,
Bernie
MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top