object variable or with block variable not set

Blue_Wings

New Member
Joined
Aug 23, 2019
Messages
11
Good morning,

I am a little bit lost here, the code was working fine, I don´t remember changing anything, and suddenly now is giving error.

Already spend a few hours around this matter and I still don´t understand why is giving this error.

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



Code:

Code:
Private Sub CommandButton1EnviarEmail_Click()



  Dim answer As Integer



  NumRecibo = Folha9.Range("B13")
  ValorRecibo = Folha9.Range("J20")

  Dim foundRng As Range

  Dim QtMeses As String

  Set foundRng = Folha10.Range("A2:A400").Find(NumRecibo)




  QtMeses = foundRng.Offset(0, 10).Value ' <<<<  The error is on this line  


    If QtMeses <> Int(QtMeses) Then

        answer = MsgBox("Tem a certeza que pretende prosseguir com o valor irregular de " + FormatNumber(ValorRecibo, 2) + "€ ?" & vbCrLf & vbCrLf & "Referente a " + QtMeses + " Meses?", vbYesNo + vbQuestion, "Enviar PDF por Email")

        If answer = vbYes Then

        Call EscreverReciboEmailemPDF

        Exit Sub

        Else

        Exit Sub

        End If

    End If


 Call EscreverReciboEmailemPDF

 End Sub

The main purpose of this code is to check a receipt number and then on that line with the "offset" method find a value to test if its "integer" or not "If QtMeses <> Int(QtMeses) Then" and then ask if the user wants to continue.
Why does this "QtMeses" doesn´t keep the value returned by the offset ?

Thank you for the help.
 
Last edited by a moderator:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
33,961
Office Version
365
Platform
Windows
Hi & welcome to MrExcel.
I suspect that this line
Code:
Set foundRng = Folha10.Range("A2:A400").Find(NumRecibo)
is not finding the value of NumRecibo and therefore foundRng is nothing
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
33,961
Office Version
365
Platform
Windows
Cross posted https://www.excelforum.com/excel-programming-vba-macros/1287516-object-variable-or-with-block-variable-not-set.html#post5181984

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 

Blue_Wings

New Member
Joined
Aug 23, 2019
Messages
11
Hi & welcome to MrExcel.
I suspect that this line
Code:
Set foundRng = Folha10.Range("A2:A400").Find(NumRecibo)
is not finding the value of NumRecibo and therefore foundRng is nothing
Yes you are right, I had the wrong position of the cell, thank you.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
33,961
Office Version
365
Platform
Windows
You're welcome & thanks for the feedback.

Please note post#3 for future reference.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
33,961
Office Version
365
Platform
Windows

Forum statistics

Threads
1,086,076
Messages
5,387,680
Members
402,073
Latest member
ThumperStrauss

Some videos you may like

This Week's Hot Topics

Top