So I have a simple little macro/sub defined when a command button is clicked. The problem is it gives me:
Run Time Error '91' : Object Variable or With Block not Set
My code is:
Dim rng As Range rng = Sheet8.Range("A12") '<< ERROR here rng.Value2 = "1"
I just want to set Cell "A12" in Sheet8.
Thanks!
Error: "Runtime Error 91" is a Visual BASIC error which means "Object variable not set". This indicates that the object was never created using the "Set" command before being used. Remedy: Be sure to use the SET statement to create the new oject.
This error has the following causes and solutions: You attempted to use an object variable that isn't yet referencing a valid object. Dim MyObject As Object ' Create object variable. Set MyObject = Sheets(1) ' Create valid object reference.
To correct this errorMake sure you aren't referring to an object variable that has been set to Nothing . Search your code for the keyword Nothing , and revise your code so that the object isn't set to Nothing until after you have referenced it. Make sure that any array variables are dimensioned before you access them.
"Object variable or With block variable not set" is a Visual Basic error message. It could originate in Excel itself, in Palisade code, or in your own macros if you have an . XLSM file. Roughly, it means that the VBA code used some variable without first initializing it properly.
You need Set with objects:
Set rng = Sheet8.Range("A12")
Sheet8 is fine.
Sheet1.[a1]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With