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:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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
 
Upvote 0
Cross posted https://www.excelforum.com/excel-pr...-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.
 
Upvote 0
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.
 
Upvote 0
You're welcome & thanks for the feedback.

Please note post#3 for future reference.
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,431
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top