+ Reply to Thread
Results 1 to 6 of 6

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

  1. #1
    Registered User
    Join Date
    09-26-2015
    Location
    Australia
    MS-Off Ver
    Office 365
    Posts
    79

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

    Hi I have a sheet that certain input is added which then has formulas to calculate certain things.

    I want to when click a button that it adds the contents of certain cells on the sheet into another table on another sheet. Once that has completed to then clear all the data that the user has imputed onto form.


    Please Login or Register  to view this content.
    I did have it all working but was cleaning up some things that and now get Run-time error 91 Object variable or With block variable not set.

    I am hoping someone can point me in the right direction.
    Attached Files Attached Files

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

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

    The problem arises when listrows.count IS zero. It assign the value zero to lrow2, which causes an error when used as the row reference to DataBodyRange.

    You need an else condition to perform some action when the listcount is zero.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    09-26-2015
    Location
    Australia
    MS-Off Ver
    Office 365
    Posts
    79

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

    Hi Andy thanks for your reply, I know something simple.

    Where exactly would I put it?

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

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

    Not sure what you want to do if no rows currently exist, although I guess it would be to add a row and assign the count again to lrow2

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-26-2015
    Location
    Australia
    MS-Off Ver
    Office 365
    Posts
    79

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

    Yes I have used the code before, it adds a row in table then adds the values into the table.

    I have tried what you have suggested but still same error.

    I have found that as had no data in table throws this error , as soon as there is data in the first row works ok.
    Last edited by SKEEEETER; 12-11-2018 at 02:01 PM.

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

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

    This change worked for me, but I don't know whether simply adding a list row is what your program requires.

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Run-time error '91': Object variable or With block variable not set when closing userform
    By bishoposiris in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-10-2016, 08:59 AM
  2. [SOLVED] Run-time error 91: Object variable or With block variable not set
    By onmyway in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-10-2015, 09:29 AM
  3. Replies: 0
    Last Post: 04-16-2013, 07:15 AM
  4. Run-time error 91 - Object variable or with block variable not set
    By twckfa16 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 12-31-2012, 06:08 PM
  5. Replies: 6
    Last Post: 12-21-2012, 08:03 AM
  6. Replies: 1
    Last Post: 09-25-2012, 08:03 PM
  7. [SOLVED] Intermittent Run-time Error 91: Object Variable or With Block variable not set
    By fraanchtoast in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-29-2012, 10:11 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1