0
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

BigBen
  • 46,229
  • 7
  • 24
  • 40
  • When using `Find`, always specify the `What`, `LookIn`, and `LookAt` parameters, then test if the `Find` succeeded using the approach in the linked thread. – BigBen Aug 17 '23 at 16:38

0 Answers0