aayaanmayank
Board Regular
- Joined
- Jul 20, 2018
- Messages
- 157
Can someone suggest the code for find and find next
Sub Find_Loop()
Dim i As Integer
Dim FirstCell As Range
Dim FoundCell As Range
Dim Rng As Range
Dim MyString As String
Dim Message As String
Set Rng = Range("A1:A10")
MyString = Range("B5").Value
Message = MyString & " not found!"
Set FoundCell = Rng.Cells(1, 1)
Set FoundCell = Rng.Find(What:=MyString, _
After:=FoundCell, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
If Not FoundCell Is Nothing Then
'Found something
Do
i = i + 1
If i = 1 Then
Set FirstCell = FoundCell
End If
If Not FoundCell Is Nothing Then
Set FoundCell = Rng.FindNext(After:=FoundCell)
End If
If Not Intersect(FoundCell, FirstCell) Is Nothing Then
'Loop is starting again
Message = "Found " & i & " matches!"
Exit Do
End If
Loop
End If
MsgBox Message
End Sub
According to your explanation and looking at your data, no rows in Sheet2 would be deleted because every combination of ID plus Name in Sheet2 exists in Sheet1. If this is not correct, please clarify again exactly what should happen using a few examples from your data and referring to specific cells, rows, columns and sheets. Which rows in Sheet2 would you expect to be deleted?
just made the slight correction for better understandingHi
720772893 exists 5 times in sheet 1, however name matches only two times. what i need if any of the ID does not match name (in sheet1) from sheet2 then it should delete all the rows which has 720772893.
So the following rows would be deleted in Sheet1. Is this correct?
72a25a783 OERGUAOM
72a25a783 8390-GMDUATRGAY HUB
72a25a783 -BROKEM ARROY #8895
72a25a783 ERGUAOM EMTERYRGAEA
720772893 ZOMA AMERGCAM YATER
720772893 MOGA AMERGCAM YATER
720772893 A AMERGCAM YATER CO