Objective: Open any workbook and run a macro, that will switch out all names and replace them with the IDs as referenced in the workbook "NameToID".
The workbook has a table with two columns, one that is a name and the other that is their associated ID. The workbook, sheet, and table have the same label of "NameToID".
The Macro is stored in my personal folder and so it is accessible to each document I open. Right now, I open up my NameToID workbook, then I open up the workbook where I want to run the macro - but when I run it I get a runtime error 9 "Subscript out of range" error. I can't figure out how to fix it. Does the NameToID workbook need to be stored somewhere in a personal folder so it is always accessible? Any help would great thanks.
Sub Multi_FindReplace()
'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 = Workbooks("NameToID").Worksheets("NameToID").ListObjects("NameToID")
'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
End If
Next sht
Next x
End Sub
ActiveWorkbook.Worksheets
Is the activeworkbook the workbook you think it is? Perhaps through adebug print activeworkbook.name
just above this line and make sure it's what you think it is. – JNevill