Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runtime error 91

Status
Not open for further replies.

vba317

Programmer
Mar 5, 2009
708
US
I am trying to display a filename in my routine but I keep on getting an Runtime error 91
Object Variable or with block variable not set.

Code:
Dim ShName As String
Dim CellRef As Range

 ShName = CellRef.Parent.Name
                                
    If Range("A" & LR1).Value < Date Then
    MsgBox ShName & " will not be saved ", vbOKCancel
        Else
   wbResults.Close SaveChanges:=True
              
              End If

Any help would be appreciated
 
It's going to be because you've definded the range object but you've tried to use it before you've set it to anything...
Code:
Dim CellRef As Range
' set the range object here before you use it
 ShName = CellRef.Parent.Name
Hope this helps

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before post
 
In other words, an Object Variable (CellRef) is not Set, just like the error says.

I admit it is not the most clear error message, as you get the same one if you do not have (for example) a proper closing End With matching an opeing With.

IMO, this is quite a difference from an object not being Set. But, shrug, there you go.

"A little piece of heaven
without that awkward dying part."

advertisment for Reese's Peanut Butter Cups (a chocolate/peanut butter confection)

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top