aayaanmayank
Board Regular
- Joined
- Jul 20, 2018
- Messages
- 157
Can someone suggest the code for find and find next
I'm still not clear which rows you want to delete in Sheet2. Could you please list the rows to be deleted in Sheet2 in the same way as I have listed them in Post #9 ?
In Sheet2 each ID number has the same name. Is there any reason why you have "THERM YOYER COMYAMY" and "therM YoYer ComYaMy" for ID: 72a02832a?
Sub MatchID()
Application.ScreenUpdating = False
Dim LastRow As Long, x As Long
LastRow = Sheets("Sheet2").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Dim ID As Range, foundID As Range, sAddr As String
For x = LastRow To 2 Step -1
Set foundID = Sheets("Sheet1").Range("A:A").Find(Sheets("Sheet2").Cells(x, 1), LookIn:=xlValues, lookat:=xlWhole)
If Not foundID Is Nothing Then
sAddr = foundID.Address
Do
MsgBox Sheets("Sheet2").Cells(x, 2)
If Sheets("Sheet2").Cells(x, 2) <> foundID.Offset(0, 1) Then
Sheets("Sheet2").Rows(x).EntireRow.Delete
Exit Do
End If
Set foundID = Sheets("Sheet1").Range("A:A").FindNext(foundID)
Loop While foundID.Address <> sAddr
sAddr = ""
End If
Next x
Application.ScreenUpdating = True
End Sub