+ Reply to Thread
Results 1 to 8 of 8

Error when run the code a second time without Re-opening the workbook

  1. #1
    Registered User
    Join Date
    10-09-2022
    Location
    London
    MS-Off Ver
    2016
    Posts
    6

    Error when run the code a second time without Re-opening the workbook

    Hi all,

    If I open the workbook and run the below code, it runs fine. However if I run the form and run the code a second time without reopening the workbook, I get method add of object listrows failed. I have added the listbox resource to UserForm_Initialize, any ideas?

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by gary lawrence; 10-09-2022 at 09:52 AM.

  2. #2
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,251

    Re: Error when run the code a second time without Re-opening the workbook


    Maybe upload some sample file ?

  3. #3
    Registered User
    Join Date
    10-09-2022
    Location
    London
    MS-Off Ver
    2016
    Posts
    6

    Re: Error when run the code a second time without Re-opening the workbook

    Hi thanks for the reply, I have uploaded a sample file

  4. #4
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,957

    Re: Error when run the code a second time without Re-opening the workbook

    Do it this way...Rowsource...I find most times has a bug...

    Please Login or Register  to view this content.


    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Sintek; 10-09-2022 at 01:28 PM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  5. #5
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Error when run the code a second time without Re-opening the workbook

    Hello.
    You are entering the data as follows:

    Please Login or Register  to view this content.
    However, you have to do it like this:

    Please Login or Register  to view this content.
    In short: when you have bound a list box (or combo box) to a range of data (in this case to a list object) via RowSource, ALWAYS unbind them first, enter or delete the data, and finally rebind them: will never let you down like this.
    Last edited by beyond Excel; 10-09-2022 at 04:59 PM.

  6. #6
    Registered User
    Join Date
    10-09-2022
    Location
    London
    MS-Off Ver
    2016
    Posts
    6

    Re: Error when run the code a second time without Re-opening the workbook

    Thank you everyone for your input It now works Perfectly

  7. #7
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,957

    Re: Error when run the code a second time without Re-opening the workbook

    Glad to have helped...Tx for rep +...
    Any other questions regarding this...just post here

  8. #8
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Error when run the code a second time without Re-opening the workbook

    Quote Originally Posted by gary lawrence View Post
    Thank you everyone for your input It now works Perfectly
    Thank you very much for adding reputation and I hope that what I suggested will be very useful to you.

+ 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 when opening workbook via vba
    By pratikshah84 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-19-2015, 10:39 AM
  2. [SOLVED] Opening new workbook and pasting values into current workbook - code issues
    By Stew1234 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-15-2014, 07:56 AM
  3. [SOLVED] Method 'Range' Error When Code is Run Automatically When Opening Workbook
    By TBrooker in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 06-26-2013, 02:46 PM
  4. Run time error 1004 only immediately after opening protected workbook
    By JoeSkittles in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-25-2013, 11:02 AM
  5. Run time error 13, when VBA workbook opening in excel 2007
    By wkslee99 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-04-2013, 03:37 AM
  6. error code while opening a workbook
    By richardconers@yahoo.com in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-28-2005, 09:30 AM
  7. run code on opening workbook and apply code to certain sheets
    By Jane in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-08-2005, 05: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