I am using basically the solution from this question find and replace values in database using an array VBA and it also works just fine. However, since a couple of days, when executing the code also replaces the lookup values in the left column of the table array and I don't know why this is happening. The lookup table is called tab_replace on the tab_replace worksheet. So, whenever the code executes the replacement on the target sheet, the value in the first column of the lookup table is also replaced.
Sub Datastream_Code_Replacement()
Dim sht As Worksheet
Dim fndList As Integer
Dim rplcList As Integer
Dim tbl As ListObject
Dim myArray As Variant
Dim TempArray As Variant
Dim targetRange As Range
Dim X As Integer
Application.DisplayAlerts = False
Set tbl = Worksheets("tab_replace").ListObjects("tab_replace")
Set TempArray = tbl.DataBodyRange
myArray = TempArray
fndList = 1
rplcList = 2
'Loop through each item in Array lists
'Loop through each worksheet in ActiveWorkbook (skip sheet with table in it)
' Skip the request table, so that no Reuters Codes are replaced
For Each sht In ActiveWorkbook.Worksheets
If sht.Name <> "CodeReplacement" Then
If sht.Name <> "tab_replace" Then
If sht.Name <> "REQUEST_TABLE" Then
If sht.Name <> "Hilfsfunktionen" Then
For X = LBound(myArray, 1) To UBound(myArray, 1)
Debug.Print (sht.Name)
Debug.Print (myArray(X, fndList))
Debug.Print (myArray(X, rplcList))
sht.Range("A2:XFD2").Replace What:=myArray(X, fndList), Replacement:=myArray(X, rplcList), _
LookAt:=xlWhole, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next X
End If
End If
End If
End If
Next sht
End Sub
Edit: This is what basically happens on the sheet with the find and replace values:
Before the execution in the first column are the lookup values, which are then overwritten.
I solved the issue by using an extra excel file to store the array and then load the data into vba and close it again before replacing the values in the original workbook.