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

Posted on 2006-03-29
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
    LVL 15

    Accepted Solution

    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

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

    Expert Comment

    You're welcome

    Don't forget to close your question
    LVL 75

    Expert Comment

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

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Suggested Solutions

    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    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…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now