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 ?
 
Upvote 0

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
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 ?

If i refer this ID 720772893 so it should delete the same from sheet2.

please understand below e.g.

sheet2 has (720772893 - RAEY AMERGCAM YATER), now my code will copy first ID and search this ID in sheet1.
IF sheet1 has this ID then it will count that howmany times this id exists.
Suppose if ID exists 5 times in sheet1 then my code will check and refer (5 times) one by one each ID (720772893 & their name) in sheet1 only and any of the ID has different name e.g. (720772893 - ZOMA AMERGCAM YATER), from sheet2 ID then it will delete the rows which has ID 720772893 in sheet2.
 
Last edited:
Upvote 0
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?
 
Upvote 0
Hopefully, I understood correctly. Try this macro:
Option Compare Text
Code:
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
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top