Hello all! I've been trying to get this macro/script to run correctly for a bit now, and it does...sorta. Found this site and thought I would ask the masters on here for help (much appreciated in advance).
I have a table of data. Column 1 and Column 2. I currently have this data in a reference worksheet (which I have called Data below) in the workbook. What I'm trying to do is run a macro that finds cell data (Column 1) and replaces it with what is located adjacent to it (Column 2) in the workbook (minus my data column sheet).
What is happening is it replaces the data and works, but after about the 13th row it replaces, it starts adding 01 onto the end of things or 0101C, etc. I'm not sure what is causing this. I usually do java/html/css/php and web-based coding, I'm not extremely familiar with excel and the VB commands/functions, but I should be able to understand the code upon seeing it. I'll post the script I have now and see if maybe I've done something wrong. I'm assuming it has something to do with the looping of the array(s) or how it composes the array from the table (not sure really).
This actually is for a manager at work that requires this or I would just say "Just use the find and replace all and change them." Any help is appreciated, thanks guys!
I have a table of data. Column 1 and Column 2. I currently have this data in a reference worksheet (which I have called Data below) in the workbook. What I'm trying to do is run a macro that finds cell data (Column 1) and replaces it with what is located adjacent to it (Column 2) in the workbook (minus my data column sheet).
What is happening is it replaces the data and works, but after about the 13th row it replaces, it starts adding 01 onto the end of things or 0101C, etc. I'm not sure what is causing this. I usually do java/html/css/php and web-based coding, I'm not extremely familiar with excel and the VB commands/functions, but I should be able to understand the code upon seeing it. I'll post the script I have now and see if maybe I've done something wrong. I'm assuming it has something to do with the looping of the array(s) or how it composes the array from the table (not sure really).
Code:
'Find/Replace All In Workbook From Table
Sub FR_All()
Dim sht As Worksheet
Dim fndList As Integer
Dim rplcList As Integer
Dim tbl As ListObject
Dim myArray As Variant
'Variable -> Data Table
Set tbl = Worksheets("Data").ListObjects("Table1")
'Data Table -> Array
Set TempArray = tbl.DataBodyRange
myArray = Application.Transpose(TempArray)
'Find/Replace (Column Definitions)
fndList = 1
rplcList = 2
'Array List Loop
For x = LBound(myArray, 1) To UBound(myArray, 2)
'Loop Each Worksheet (minus Data) & Change Entries
For Each sht In ActiveWorkbook.Worksheets
If sht.Name <> tbl.Parent.Name Then
sht.Cells.Replace what:=myArray(1, x), Replacement:=myArray(2, x), _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
End If
Next sht
Next x
End Sub
This actually is for a manager at work that requires this or I would just say "Just use the find and replace all and change them." Any help is appreciated, thanks guys!
Last edited by a moderator: