+ Reply to Thread
Results 1 to 10 of 10

Help with userform code looping and bringing error

  1. #1
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Help with userform code looping and bringing error

    Hello,

    I have the following code:

    Please Login or Register  to view this content.
    However, if there is only one entry that matches the search criteria put into the active cell, then it brings up an error saying "runtime error 91, object variable or with block variable not set". It errors on this piece of code:

    Please Login or Register  to view this content.
    However when there is more than 1 entry that matches the criteria, it works perfectly

    Can anyone help?

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Help with userform code looping and bringing error

    Does it stop if you use next code

    Please Login or Register  to view this content.
    It will be really easier if you can send a sample of your file
    - Battle without fear gives no glory - Just try

  3. #3
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Help with userform code looping and bringing error

    PCI

    Which code are you saying I should try replacing with your suggestion?

    Thanks

  4. #4
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Help with userform code looping and bringing error

    Replace

    Please Login or Register  to view this content.
    by

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Help with userform code looping and bringing error

    That brings up the userform (when it shouldn't) with no entries, so doesn't sort it unfortunately.

    See attached sample file

    Sample 11-09-15.xlsm

  6. #6
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Help with userform code looping and bringing error

    Hi there,

    The problem is being caused by the highlighted line:

    Please Login or Register  to view this content.
    The calling routine contains the line:

    Please Login or Register  to view this content.
    but before that command can be executed, the UserForm has already been unloaded.

    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  7. #7
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Help with userform code looping and bringing error

    Hi Greg,

    That does look like the problem, although I'm now confused as to how to solve it whilst still getting the userform to close if there is only 1 matching entry?

    Taking out the unload me means that the userform just stays open with the one matching entry in the listbox.

  8. #8
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Help with userform code looping and bringing error

    Hi again,

    Try using the following versions of your routines:

    Please Login or Register  to view this content.
    and:


    Please Login or Register  to view this content.

    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  9. #9
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Help with userform code looping and bringing error

    Thank you! All sorted

  10. #10
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Help with userform code looping and bringing error

    Hi again,

    Great! Glad to have been able to help.

    Many thanks for your feedback and also for the Reputation increase - much appreciated.

    Best regards,

    Greg M

+ 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. Macro code to show userform bringing runtime error 1004
    By ExcelFailure in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-11-2015, 02:59 AM
  2. [SOLVED] Logic Error - Code Is Looping Back
    By goss in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-06-2014, 10:04 PM
  3. [SOLVED] Userform macro preventing Windows.Activate from bringing window to front
    By bfs3 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-16-2014, 10:50 PM
  4. VBA Looping code help need for Multiplication Table in UserForm
    By krjoshi in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-24-2011, 02:04 PM
  5. userform with looping code
    By 00Able in forum Excel Programming / VBA / Macros
    Replies: 36
    Last Post: 02-22-2011, 09:10 PM
  6. UserForm Code Error
    By Mooseman60 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-04-2010, 09:05 AM
  7. [SOLVED] Looping procedure calls userform; how to exit loop (via userform button)?
    By KR in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-27-2005, 08:05 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