+ Reply to Thread
Results 1 to 12 of 12

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

  1. #1
    Registered User
    Join Date
    09-06-2013
    Location
    Northamptonshire, England
    MS-Off Ver
    Excel 2003
    Posts
    45

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

    Hello All,

    I am having an issue with a line of code in a macro that otherwise works perfectly week in week out.

    Please Login or Register  to view this content.
    Please could somebody advise me as to what needs fixing in this line of code? I cant quite figure out what is different about this data set that is causing this error when it usually ruins without error.

    Thank you in advance

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

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

    Did you?

    Dim rngX as Range

  3. #3
    Registered User
    Join Date
    09-06-2013
    Location
    Northamptonshire, England
    MS-Off Ver
    Excel 2003
    Posts
    45

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

    Hi John,

    Thanks for the response.

    Yes this is the full section of the macro.

    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

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

    Try:

    Please Login or Register  to view this content.
    AFAIK rows before columns when using cells as range.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

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

    Which line do you actually get the error on?
    If posting code please use code tags, see here.

  6. #6
    Registered User
    Join Date
    09-06-2013
    Location
    Northamptonshire, England
    MS-Off Ver
    Excel 2003
    Posts
    45

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

    Hmm, Thanks for the feedback John but that appeared to give the same error.

    Norie i get an error on this line:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    09-06-2013
    Location
    Northamptonshire, England
    MS-Off Ver
    Excel 2003
    Posts
    45

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

    Apologies... the error now reads
    "Run-time error '9':
    Subscript out of range"

  8. #8
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

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

    That means you don't have a worksheet with the name specified in column A on one of your processed rows. When the error occurs double-check the contents of that cell.
    Remember what the dormouse said
    Feed your head

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

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

    What happens if you change the code to this?
    Please Login or Register  to view this content.
    Last edited by Norie; 11-18-2014 at 10:05 AM.

  10. #10
    Registered User
    Join Date
    09-06-2013
    Location
    Northamptonshire, England
    MS-Off Ver
    Excel 2003
    Posts
    45

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

    Norie that seems to work perfectly.

    Thank you. Much appreciated

    Please advise what that must mean in regards to why the the initial issue came about?

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

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

    When you say it's working perfectly, does the message box never appear?

    What I thought was wrong with the original code was that find was failing to find what you were looking for on the sheet you were looking on.

    When Find fails it returns Nothing, and you can't offset from Nothing.

    The code I posted checks if Find was succesful and only then does the offset and executes the rest of the code.

    If Find wasn't succesful the message box would be displayed.

  12. #12
    Registered User
    Join Date
    09-06-2013
    Location
    Northamptonshire, England
    MS-Off Ver
    Excel 2003
    Posts
    45

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

    The message box did appear for one line of data in the one of the data sheets. After skipping that the rest of the macro ran without error.

+ 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. Run TIme error 91 Object variable or with block variable not set
    By flex30 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-23-2013, 11:34 AM
  2. Replies: 0
    Last Post: 04-16-2013, 07:15 AM
  3. Replies: 6
    Last Post: 12-21-2012, 08:03 AM
  4. Replies: 1
    Last Post: 09-25-2012, 08:03 PM
  5. [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

Tags for this Thread

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