HoboEconomist
New Member
- Joined
- May 6, 2020
- Messages
- 5
- Office Version
- 2016
- Platform
- Windows
Hi all,
Sorry for the beginner VBA question - I've been stuck for a while and haven't been able to adapt any answers from this forum to quite get the results I would like.
I have a range (B46:C54) on multiple sheets that contains values that need to be used in a find and replace. B46:B54 contains the "find" values, while C46:C54 contains the "replace" value. I have text strings in cells F71:F80 where I want the find and replace to occur.
I had previously set this up using the following code:
While this works just fine, it turns out that one of the add-ins I need to use deletes all defined tables after running (I am very sad about this). So ideally, I need a piece of code that does the same thing, but doesn't use tables to do it. It would be great if someone could point me in the right direction here!
Sorry for the beginner VBA question - I've been stuck for a while and haven't been able to adapt any answers from this forum to quite get the results I would like.
I have a range (B46:C54) on multiple sheets that contains values that need to be used in a find and replace. B46:B54 contains the "find" values, while C46:C54 contains the "replace" value. I have text strings in cells F71:F80 where I want the find and replace to occur.
I had previously set this up using the following code:
VBA Code:
Sub Multi_FindReplace()
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 table
Set tbl = ActiveSheet.ListObjects("Email_Controls")
'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
'Copy Text from Email Body to Email Output section
ActiveSheet.Range("F46:F55").Copy
ActiveSheet.Range("F71:F80").PasteSpecial Paste:=xlPasteValues
'Loop through each item in Array lists and conduct find/replace
For x = LBound(myArray, 1) To UBound(myArray, 2)
ActiveSheet.Range("F71:F80").Replace What:=myArray(fndList, x), Replacement:=myArray(rplcList, x), _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next x
End Sub
While this works just fine, it turns out that one of the add-ins I need to use deletes all defined tables after running (I am very sad about this). So ideally, I need a piece of code that does the same thing, but doesn't use tables to do it. It would be great if someone could point me in the right direction here!