I had a working macro, then I copied it to another excel workbook that is exactly the same but with new data and all of the sudden the macro doesn’t work anymore.
It gives a run time error 91. I cannot figure out which variable is not set or what is wrong (and why it is wrong all of the sudden)
Thnx for your help
Code
It gives a run time error 91. I cannot figure out which variable is not set or what is wrong (and why it is wrong all of the sudden)
Thnx for your help
Code
Code:
Sub FindStock()
Dim rRange As Range
Dim rCell As Range
Dim Dte As Variant
Dim CUSIP As Long
Dim lcount As Long
Dim lOccur As Long
Dim NCalls As Long
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
With Sheets("OutputCall").Range("a1")
NCalls = Range(.Cells(1, 1), .End(xlDown)).Rows.Count - 2
End With
With Sheets("Stock").Range("a1")
Set rRange = Range(.Cells(1, 1), .End(xlDown).End(xlToRight))
End With
Set rCell = rRange.Cells(1, 1)
For i = 0 To 1
Dte = Sheets("OutputCall").Range("B2").Offset(i, 0)
CUSIP = Sheets("OutputCall").Range("M2").Offset(i, 0)
lOccurs = Application.WorksheetFunction.CountIf(rRange.Columns(1), Dte)
For lcount = 0 To lOccurs
Set rCell = rRange.Columns(1).Find(what:=Dte, after:=rCell, _
LookIn:=xlValues, LookAt:=xlWhole, searchorder:=xlByRows, _
searchdirection:=xlNext, MatchCase:=False)
If rCell(1, 3) Like CUSIP Then Sheets("OutputCall").Range("n2").Offset(i, 0) = rCell(1, 7)
If Sheets("OutputCall").Range("n2").Offset(i, 0) = rCell(1, 5) Then Exit For
Next lcount
Next i
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub