Hi,
I am working on XL database and have two codes for pulling data out from the main sheet on to sheet2 and another code to put it back after I update info.
The 'replace' code seems to be having problem and keep giving me "match not found for row 2" message.
Appreciate your help on this. Here is the code:
Thank you.
Sub replace()
Dim ws As Worksheet
Dim wsList As Worksheet
Dim searchRng As Range
Set wsList = Sheets("HajiList")
Set searchRng = wsList.Columns(8)
Set ws = Sheets("Sheet2")
lastRow = ws.Cells(ws.Rows.Count, 8).End(xlUp).Row
For i = lastRow To 2 Step -1
'unique identifier is in column E
myID = Range("E" & i)
'find matching row number on MyList sheet
matchRow = 0
On Error Resume Next
matchRow = Application.WorksheetFunction.Match(myID, searchRng, 0)
If matchRow > 0 Then
'we found a match
ws.Rows(i).Copy Destination:=wsList.Range("A" & matchRow)
ws.Rows(i).Delete
Else
MsgBox "Match not found for row " & i
End If
Next i
End Sub
Bookmarks