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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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,223,897
Messages
6,175,271
Members
452,628
Latest member
dd2

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