Professional Documents
Culture Documents
Sub FindReplaceAll()
'SOURCE: www.TheSpreadsheetGuru.com
fnd = "April"
rplc = "May"
SearchFormat:=False, ReplaceFormat:=False
End Sub
Sub FindReplaceAll()
'SOURCE: www.TheSpreadsheetGuru.com
fnd = "April"
rplc = "May"
For Each sht In ActiveWorkbook.Worksheets
SearchFormat:=False, ReplaceFormat:=False
Next sht
End Sub
If you need to perform a bunch of find and replace actions at once, you can use Arrays to store your
values.
Sub Multi_FindReplace()
'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault
Dim x As Long
SearchFormat:=False, ReplaceFormat:=False
Next sht
Next x
End Sub
You can also read my post describing how you can populate your Array variables from an Excel
spreadsheet Table if you already have you list handy on your spreadsheet (sometimes it can be a pain
typing all your values out inside your VBA code). Below is an example of how this can be accomplished.
Sub Multi_FindReplace()
'PURPOSE: Find & Replace a list of text/values throughout entire workbook from a table
'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault
myArray = Application.Transpose(TempArray)
fndList = 1
rplcList = 2
'Loop through each worksheet in ActiveWorkbook (skip sheet with table in it)
SearchFormat:=False, ReplaceFormat:=False
End If
Next sht
Next x
End Sub
You may find yourself wanting to report out how many changes were made after your code has run. You
can accomplish this by using the COUNTIF() function to count how many cells contain your Find value
before you actually perform your find & replace.
The one downside to using the COUNTIF() function is it will not count multiple occurrences within a
single cell. I could not figure out a way around this and if you know of a way to accomplish this please let
me know in the comments section (this article might point you in the right direction).
Sub FindReplaceAll_CountReplacements()
'PURPOSE: Find & Replace text/values throughout entire workbook, notify user of how many cells were
affected
'SOURCE: www.TheSpreadsheetGuru.com
fnd = "April"
rplc = "May"
SearchFormat:=False, ReplaceFormat:=False
Next sht
MsgBox "I have completed my search and made replacements in " & ReplaceCount & " cell(s)."
End Sub
Sub qwerty()
Dim rFirst As Range, r As Range
Dim A As Range
Set A = Range("A:A")
Do
If rFirst Is Nothing Then
Set rFirst = A.Find(What:=1, After:=A(1))
Set r = rFirst
Else
Set r = A.Find(What:=1, After:=r)
If r.Address = rFirst.Address Then Exit Do
End If
MyString = MyString & " " & r.Offset(0, 1)
Loop
MsgBox MyString
End Sub