Copied working macro to another workbook, error 91

Whoeiii

New Member
Joined
Feb 4, 2011
Messages
14
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

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
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi there,

If the error message is actually "Run-time error '9':" then it's because there's no tab in the new workbook either called "OutputCall" or "Stock" (or both are missing).

HTH

Robert
 
Upvote 0
it's error 91. I checked all the names again. I only find that stock was once not written with a capital. fixed it, but still got run time error 91.

So any other ideas.
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,799
Members
452,943
Latest member
Newbie4296

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