+ Reply to Thread
Results 1 to 15 of 15

Error on userform remove button click

  1. #1
    Registered User
    Join Date
    05-23-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    79

    Exclamation Error on userform remove button click

    Hello,

    I am in a tight jam, as my project is due tomorrow and I am now encountering an error for the first time. My assumption is that I coded for Excel 2003 and am testing on excel 2007 right now, but I cannot confirm that is the cause of the error.

    I have a user form with two source listboxes: (1) listcg (2) listmc that are added to listselected when the "add button" is clicked. The problem is now removing an item from the listselected lsitbox back to the original source listbox.

    I select ALL of the items in listCG and move them to listselected. Now the error ONLY occurs when I remove the items from listselected in a different order. In other words, the code works if I have items remaining in listCG still or if I remove from listSelected in order top to bottom.

    The code is meant to return the item to the exact order it was in before adding to listSelected = alphabetically. If it was not originally in listCG, it checks to add back to listMC.

    again, the code only breaks down when there are no items remaining in listCG or when removed out of order. breakdown point is

    Please Login or Register  to view this content.
    PLEASE HELP!

    Please Login or Register  to view this content.

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

    Re: Error on userform remove button click

    What is the error?

  3. #3
    Registered User
    Join Date
    05-23-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Error on userform remove button click

    run-time error '-2147024809 (80070057)':

    Invalid Argument

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

    Re: Error on userform remove button click

    What are the arguments, c01 and i when you get the error?

  5. #5
    Registered User
    Join Date
    05-23-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Error on userform remove button click

    well i is the position of the selected item in the original array (integer) and c01 is the name of the item selected (string)

    is that what you are asking for?

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

    Re: Error on userform remove button click

    Not really.

    What are there actual values when you get the error?

  7. #7
    Registered User
    Join Date
    05-23-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Error on userform remove button click

    i=4
    c01=atlanta

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

    Re: Error on userform remove button click

    I can't see how that would cause a problem.

    How is listCG initially populated?

  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: Error on userform remove button click

    I've done some checks and if the listbox is empty that will cause the error you describe.

    That's probably because there is no 'position' 1 yet in the listbox.

  10. #10
    Registered User
    Join Date
    05-23-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Error on userform remove button click

    any ideas on how to bypass this error. I need the listbox to remain sorted as it was originally every time i add to it (using the remove button)

  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: Error on userform remove button click

    Is listCG empty?

    If it is why not just repopulate it as you initially do?

  12. #12
    Registered User
    Join Date
    05-23-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Error on userform remove button click

    on the userform, i remove from listCG and transfer to listSelected using an ADD button. Assuming I transfer all items from listCG, I now create the empty listbox.

    I am trying to have the REMOVE button send items back one-by-one to listCG while remaining sorted (original position)...i can get it to return to the listCG box, but not remain alphabetically sorted

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

    Re: Error on userform remove button click

    Why do you need to 'send' them back?

    Can't you just repopulate the listbox with the original values, and remove them from listSelected?

  14. #14
    Registered User
    Join Date
    05-23-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Error on userform remove button click

    so simply listCG.additem? How can I then get the list to remain alphabetically sorted? Thanks again for your help Norie

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

    Re: Error on userform remove button click

    It might not be AddItem - I don't know how you originally populated listCG.

    Perhaps if you attached a sample workbook it might help.
    Last edited by Norie; 10-11-2012 at 08:48 AM.

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

    Re: Error on userform remove button click

    You need to post example workbook.
    Cheers
    Andy
    www.andypope.info

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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