Sub FindIns()
Dim Rng As Range
Dim InsuredCell As Range
Dim CopyArticle As String
Dim FoundArticle As Range
Dim Insured As String
Dim FirstCell As String
Insured = "Ins" 'To check the Ins mark for articles
Set Rng = Sheets(5).Range("D:D")
'using Find method to find the cell number where the Ins first appeared
Set InsuredCell = Rng.Find(What:=Insured, MatchCase:=True)
'error handling if the Ins is not on the list
If InsuredCell Is Nothing Then
MsgBox "No Ins of such name is found"
Else
'running through the Rng range to find Ins articles information
FirstCell = InsuredCell.Address
Do
CopyArticle = InsuredCell.Offset(0, -1).Value
Set FoundArticle = Sheets(7).Range("E:E").Find(What:=CopyArticle, MatchCase:=True)
FoundArticle.Offset(0, 2).Value = "X"
Set InsuredCell = Rng.FindNext(InsuredCell)
Loop While InsuredCell.Address <> FirstCell
End If
End Sub
Here in this code InsuredCell value is getting Nothing, even though there are other Ins in different rows. And Run time error 91 is displayed