I'm using a Find and Replace macro that refers to an array table.
I just HAVE to be missing something. There's NO way that the only way to reference an array table that stores values for Find/Replace macro is from only in the ActiveWorkbook I'm currently working; where I have to copy and paste the table over into a new sheet for every new Workbook that I want to run this macro! No way.
I've looked everywhere and can't believe that this is not a more common issue, or I'm totally missing the boat!
I really want to be able to use and refer to my Personal.xlsb default template for the array table, because it’s ALWAYS open, of course. How can I set up this reference?
This is the current reference from macro below and only way I can get it to work:
(Referring to a sheet inside the ActiveWorkbook)
Here’s what I’ve tried instead, in an effort to reference another file, even location:
I’ve even tried the absolute file path, nothing.
As soon as I change it to try to refer to Personal.xlsb or location I get Error 9 : subscript out of range
Right now my Array Table MUST be copied into the Activeworkbook on the ‘Table1’ Sheet (Tab), every time I want to use this macro!
I just HAVE to be missing something. There's NO way that the only way to reference an array table that stores values for Find/Replace macro is from only in the ActiveWorkbook I'm currently working; where I have to copy and paste the table over into a new sheet for every new Workbook that I want to run this macro! No way.
I've looked everywhere and can't believe that this is not a more common issue, or I'm totally missing the boat!
I really want to be able to use and refer to my Personal.xlsb default template for the array table, because it’s ALWAYS open, of course. How can I set up this reference?
This is the current reference from macro below and only way I can get it to work:
Code:
'Create variable to point to your table
Set tbl = Worksheets("Table1").ListObjects("Table1")
Here’s what I’ve tried instead, in an effort to reference another file, even location:
Code:
Set tbl = Personal.xlsb("Sheet1").ListObjects("Table1")
------
I thought I had it With this one For sure!!
Set tbl = Workbooks("Personal.xlsb").Sheets("Table1").ListObjects("Table1")
-------
Set wb1 = Application.Workbooks("Personal.xlsb")
Set tbl = wb1("Table1").ListObjects("Table1")
-------
Set wb1 = Workbooks("Personal.xlsb").Sheets("Table1")
Set tbl = wb1("Table1").ListObjects("Table1")
-------
Set wb1 = Workbooks("Personal.xlsb").Sheets("Table1")
Set tbl = wb1.ListObjects("Table1")
-------
I’ve even tried the absolute file path, nothing.
As soon as I change it to try to refer to Personal.xlsb or location I get Error 9 : subscript out of range
Right now my Array Table MUST be copied into the Activeworkbook on the ‘Table1’ Sheet (Tab), every time I want to use this macro!
Code:
Sub FindReplace_Multi_ActivesheetOnly()
'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
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False
'Create variable to point to your table
Set tbl = Worksheets("Table1").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 <> tbl.Parent.name Then
ActiveSheet.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
Last edited: