Runtime Error 91 : Object variable or With block variable not set

mars07

New Member
Joined
Dec 28, 2010
Messages
30
Hi

I am getting Run time Error 91 on spread where I am setting my range.

I used exactly same code (100% same), just changed the name in another program and it was working fine. I dont know whats wrong here...

Only difference is, in that program, a button was activating the procedure and and in this program I want the "Exit" event to trigger the procedure... Can some one tell me, what going wrong ?

HTML:
Dim Code As Variant
Dim spread As Range
Dim looper As Long
Static flagger As Long
spread = "A1:Z99"
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Try

Rich (BB code):
Dim Code As Variant
Dim spread As Range
Dim looper As Long
Static flagger As Long
Set spread = Range("A1:Z99")
 
Upvote 0
Is that all the code?

You mention an Exit event is triggering this, can you post all the code?
 
Upvote 0
HTML:
Private Sub Supplier_Code_Exit(ByVal Cancel As MSForms.ReturnBoolean)

Dim Code As Variant
Dim spread As Double
Dim looper As Long
Static flagger As Long
Set spread = ("A1:Z99")

If Me.Supplier_Code = "" Then
MsgBox ("Supplier Code Must be entered")
Cancel = True
Me.Supplier_Code.SetFocus
End If

For looper = 1 To 100

    If (Sheets("Suppliers").Cells(c, 1).Value = Me.Supplier_Code) Then
    flagger = flagger + 1
    End If
Next looper

If (flagger > 0) Then
    Cancel = True
    Sheets("Suppliers").Activate
    Me.Pro_Code = WorksheetFunction.VLookup(Me.Supplier_Code.Value, Range(spread), 5, False)
    Me.Pro_Details = WorksheetFunction.VLookup(Me.Supplier_Code.Value, Range(spread), 6, False)
    Me.Qty_Avail = WorksheetFunction.VLookup(Me.Supplier_Code.Value, Range(spread), 8, False)
    Me.Cost_Unit = WorksheetFunction.VLookup(Me.Supplier_Code.Value, Range(spread), 7, False)
    Me.Total_Cost = WorksheetFunction.VLookup(Me.Supplier_Code.Value, Range(spread), 10, False)
Else

    If (MsgBox("Supplier does not Exist, Do you want to Check again", vbYesNo) = vbYes) Then
    Cancel = True
    Me.Supplier_Code = ""
    Me.Supplier_Code.SetFocus
    Else
    Unload Me
    End If
    
End If
End Sub
 
Upvote 0
also to mention that exact same code was working for me in a search button in another program
 
Upvote 0
Did you actually make the change that VoG suggested?
 
Upvote 0
you can see it in the code for ure self it is there... prior to change it was simply

spread = "A1:Z99"

i really cant understand... why it is working in one program perfectly ok and why on here... is it linked to the fact that there i am using button and this is and exit event function ?
 
Upvote 0
If I define

HTML:
Dim Spread as Double

It gives error "Object Required"

and if I define

HTML:
Dim Spread as Range

it says Type Mis-Match .... In my last program i used it as double though
 
Upvote 0
You have this in your code:
Code:
Set spread = ("A1:Z99")
Where's the Range("A1:Z99") that was suggested?

Also is spread meant to be a reference to a range?

If it is then you shouldn't need to wrap it in Range in the Worksheet.Function.Vlookup later in the code.
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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