Run-time error'91' : Object variable or With block variable not set

Posted on 2006-03-29
Medium Priority
Last Modified: 2013-12-25
The following macro generate error message 'Run-time error '91': Object variable or With block variable not set' error. This script has been around for years without error and nobody changed this macro as well until the error pop up suddently today.

Private Function getParamVal(stParam As String) As Variant
  Dim cParam As Range
  Set cParam = getParamCell(stParam, False)
  If cParam Is Nothing Then
    Set getParamVal = Nothing
    Exit Function
  End If
  getParamVal = cParam.Offset(0, 1).Value

getParamCell Function
Private Function getParamCell(stParam As String, Optional bAdd As Boolean = True) As Range
  Dim iTailRow As Integer
  If gcParam Is Nothing Then    ' Get pivot cell if not defined yet
    Set gcParam = gwInfo.Cells.Find("Parameters", _
      After:=gwInfo.Cells(1, 1), SearchOrder:=xlByColumns, LookIn:=xlValues, LookAt:=xlWhole)
  End If
  ' Get cell
  Set getParamCell = gwInfo.Cells.Find(stParam, After:=gcParam, _
    SearchOrder:=xlByColumns, LookIn:=xlValues, LookAt:=xlWhole)
  If (getParamCell Is Nothing) And (bAdd) Then  'Add it at tail
    If IsEmpty(gcParam.Offset(2, 0)) Then 'Beware!
      iTailRow = gcParam.Row + 2
      iTailRow = gcParam.End(xlDown).Row + 1
    End If
    Set getParamCell = gwInfo.Cells(iTailRow, gcParam.Column)
    getParamCell.Value = stParam
  End If
End Function

The error comes up when trying to execute 'Exit Function'  on function getParamVal.

Any idea on why this is happening ?
Thank you in advance !
Question by:LuckyLuciano
  • 2
LVL 15

Accepted Solution

Computron earned 500 total points
ID: 16329269
Since this refers to an object and not a function, I think it can be changed from

  If cParam Is Nothing Then
    Set getParamVal = Nothing
    Exit Function
  End If


 If cParam Is Nothing Then Exit Function

Author Comment

ID: 16329366
Computron, it works now, thank you so much for your help!
LVL 15

Expert Comment

ID: 16329438
You're welcome

Don't forget to close your question
LVL 75

Expert Comment

by:Anthony Perkins
ID: 16335180
Do you need help closing this question?

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month17 days, 10 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question