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

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
    Else
      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 !
Regards,
DJ
LuckyLucianoAsked:
Who is Participating?
 
ComputronCommented:
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

to

 If cParam Is Nothing Then Exit Function
0
 
LuckyLucianoAuthor Commented:
Computron, it works now, thank you so much for your help!
0
 
ComputronCommented:
You're welcome

Don't forget to close your question
0
 
Anthony PerkinsCommented:
Do you need help closing this question?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.