Results 1 to 7 of 7

Thread: object variable or with block variable not set
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Aug 2019
    Location
    Portugal
    Posts
    11
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default object variable or with block variable not set

    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 Fluff; Aug 23rd, 2019 at 09:30 AM. Reason: Added code tags

  2. #2
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    29,229
    Post Thanks / Like
    Mentioned
    483 Post(s)
    Tagged
    49 Thread(s)

    Default Re: object variable or with block variable not set

    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
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  3. #3
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    29,229
    Post Thanks / Like
    Mentioned
    483 Post(s)
    Tagged
    49 Thread(s)

    Default Re: object variable or with block variable not set

    Cross posted https://www.excelforum.com/excel-pro...ml#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.
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  4. #4
    New Member
    Join Date
    Aug 2019
    Location
    Portugal
    Posts
    11
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: object variable or with block variable not set

    Quote Originally Posted by Fluff View Post
    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.

  5. #5
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    29,229
    Post Thanks / Like
    Mentioned
    483 Post(s)
    Tagged
    49 Thread(s)

    Default Re: object variable or with block variable not set

    You're welcome & thanks for the feedback.

    Please note post#3 for future reference.
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  6. #6
    New Member
    Join Date
    Aug 2019
    Location
    Portugal
    Posts
    11
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: object variable or with block variable not set

    Quote Originally Posted by Fluff View Post
    You're welcome & thanks for the feedback.

    Please note post#3 for future reference.
    I will, Thank you.

  7. #7
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    29,229
    Post Thanks / Like
    Mentioned
    483 Post(s)
    Tagged
    49 Thread(s)

    Default Re: object variable or with block variable not set

    Cheers
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •