tmteast
New Member
- Joined
- Apr 12, 2021
- Messages
- 7
- Office Version
- 365
- 2019
- 2016
- Platform
- Windows
- MacOS
- Web
Hello, I am working on a Macro and I am very close. When the Find/Replace happens it is replacing more than I want.
I am not a coder and would like help finishing this script I have borrowed from thespreadsheetguru.
When the find/replace happens I want it to only Search in one Column G:G in the Current Sheet. I have added what I thought would work in a few places but cannot seem to keep it bound to the one column.
Thanks in advance.
Sub AccountsPStoQB()
'
' AccountsPStoQB Macro
'
'
'PURPOSE: Find & Replace a list of text/values throughout entire workbook from a table
'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault
Dim sht As Worksheet
Dim fndList As Integer
Dim rplcList As Integer
Dim tbl As ListObject
Dim myArray As Variant
'Create variable to point to your table
Set tbl = Worksheets("Accounts").ListObjects("Table7")
'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 <> tbl.Parent.Name Then
sht.Cells.Replace What:=myArray(fndList, x), Replacement:=myArray(rplcList, x), _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
End If
Next sht
Next x
End Sub
I am not a coder and would like help finishing this script I have borrowed from thespreadsheetguru.
When the find/replace happens I want it to only Search in one Column G:G in the Current Sheet. I have added what I thought would work in a few places but cannot seem to keep it bound to the one column.
Thanks in advance.
Sub AccountsPStoQB()
'
' AccountsPStoQB Macro
'
'
'PURPOSE: Find & Replace a list of text/values throughout entire workbook from a table
'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault
Dim sht As Worksheet
Dim fndList As Integer
Dim rplcList As Integer
Dim tbl As ListObject
Dim myArray As Variant
'Create variable to point to your table
Set tbl = Worksheets("Accounts").ListObjects("Table7")
'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 <> tbl.Parent.Name Then
sht.Cells.Replace What:=myArray(fndList, x), Replacement:=myArray(rplcList, x), _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
End If
Next sht
Next x
End Sub