VBA learner ITG
Active Member
- Joined
- Apr 18, 2017
- Messages
- 272
- Office Version
- 365
- Platform
- Windows
- MacOS
Hi all,
I was wondering if I could get your advice to why this piece of code isnt ignoring the worksheets called: "Control" & "Data".
This is the piece of code that I cannot understand why it doesnt ignore the worksheets when its ran:
FULL CODE BELOW
I was wondering if I could get your advice to why this piece of code isnt ignoring the worksheets called: "Control" & "Data".
This is the piece of code that I cannot understand why it doesnt ignore the worksheets when its ran:
Code:
For Each sht In ActiveWorkbook.Worksheets
If sht.Name = "control" Or _
sht.Name = "Data" Then
'Do Nothing
Else
FULL CODE BELOW
VBA Code:
Sub Multi_FindReplace()
'PURPOSE: Find & Replace a list of text/values throughout entire workbook from a table
Dim sht As Worksheet
Dim fndList As Integer
Dim rplcList As Integer
Dim tbl As ListObject
Dim myArray As Variant
Dim ReplaceCount As Long
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False
'Create variable to point to your table
Set tbl = Worksheets("CONTROL").ListObjects("Table1")
'Create an Array out of the Table's Data
Set TempArray = tbl.DataBodyRange
myArray = Application.Transpose(TempArray)
'Designate Columns for Find/Replace data
fndList = 1
rplcList = 2
'Loop through each item in Array lists
For x = LBound(myArray, 1) To UBound(myArray, 2)
'Loop through each worksheet in ActiveWorkbook (skip sheet with table in it)
For Each sht In ActiveWorkbook.Worksheets
If sht.Name = "control" Or _
sht.Name = "Data" Then
'Do Nothing
Else
ReplaceCount = ReplaceCount + Application.WorksheetFunction.CountIf(sht.Cells, "*" & fnd & "*")
sht.Cells.Replace What:=myArray(fndList, x), Replacement:=myArray(rplcList, x), _
LookAt:=xlWhole, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
End If
Next sht
Next x
MsgBox "I have completed my search and made replacements in " & ReplaceCount & " cell(s)."
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.EnableEvents = True
End Sub