code runs, however does not find/replace values.
I believe issues are in the for loop with worksheets and replacement method
Sub UGA()
'PURPOSE: Loop through all Excel files in a user specified folder and perform a set task on them
Dim wb As Workbook
Dim ws As Worksheet
Dim myPath, myFile, myExtension As String
Dim fnd, rep As Variant
Dim FldrPicker As FileDialog
'Loop through each Excel file in folder
Do While myFile <> ""
'Set variable equal to opened workbook
Set wb = Workbooks.Open(Filename:=myPath & myFile)
'Ensure Workbook has opened before moving on to next line of code
DoEvents
'find and replace with blank
fnd = "find this"
rep = ""
'Loop through each worksheet in ActiveWorkbook
For Each ws In ActiveWorkbook.Worksheets
ws.Cells.Replace What:=fnd, Replacement:=rep, _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next ws
'Save and Close Workbook
wb.Close SaveChanges:=True
'Ensure Workbook has closed before moving on to next line of code
DoEvents
'Get next file name
myFile = Dir
Loop
'Message Box when tasks are completed
MsgBox "Complete!"
End Sub
expected to find defined value and replace with blanks ("")
Through Workbooks and Worksheets
Your code is relying on the
Active Workbook
which is the likely culprit.Change
For Each ws In ActiveWorkbook.Worksheets
toFor Each ws in wb.Worksheets
to explicitly refer to the workbook.You have also dimmed you strings
fnd
&rep
as variants. These should be strings and the proper way to shorthand declare two variables isDim fnd as String, rep as String
. The way you went about is actually declaring both variables as variant.