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"
 
HTML:
Dim Code As Variant
Dim spread As Double
Dim looper As Long
Static flagger As Long
[B][COLOR="Red"]Set spread = ("A1:Z99")[/COLOR][/B]

Spread refers to a range in Supplier sheet... While using Vlookup function if I type the code as

HTML:
worksheetfunction.vlookup(Lookup Value, Range ("A1:Z99"), Column Index, True/False)

It gives error... I read some where that range has to be defined as a variable and then given as

HTML:
Range = "A1:Z99"
worksheetfunction.vlookup(Lookup Value, Range (Range), Column Index, True/False)
 
Upvote 0

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
OK

Dim spread as Range

HTML:
spread = Range ("A1:Z99")

Now it is not giving error, but now there is problem with Vlookup function... let me see wht it is and I'll get back to u guys... thanks for all the help
 
Upvote 0
As VoG said you should have

Code:
Dim spread as Range

and also use "Set" as VoG mentioned since you are establishing an Object and without Set you will get the "Object variable or with block variable not set" error

Code:
Set spread as Range("A1:Z99")

Then within your Vlookup code it should look like this

Code:
WorksheetFunction.VLookup(Me.Supplier_Code.Value, spread, 5, False)
 
Upvote 0
thanks man... I am not a programmer basically... but I guess with you guys around it will not be hard to become one :)
 
Upvote 0
I am not a programmer either. I just keep hacking away at it.

VoG and Norie are both exceptional experts.

Keep going, there are no silly questions.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,430
Messages
6,124,846
Members
449,194
Latest member
HellScout

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