+ Reply to Thread
Results 1 to 11 of 11

Exiting Excel fires Change Event on ListBox

  1. #1
    Registered User
    Join Date
    04-17-2014
    Location
    Ireland
    MS-Off Ver
    Excel 2013
    Posts
    6

    Exiting Excel fires Change Event on ListBox

    Hi all,

    I'm struggling with an issue and hoping someone may be able to help.

    I've created a Change Event for a listbox which is working well. The purpose of this is to record the selected items from the multi select listbox and store them on the spreadsheet & clear the previously stored list.

    The problem is when I try to close the application using the top right 'X'. I get a Run time error, ClearContents method of Range class failed. When I debug this I can see that the Change Event for the List box is the cause, in particular, the line which clears the range.

    2 questions....

    1, Why is this Change Event firing when exiting the application? It doesn't seem to if I exit the workbook via File-> Close. Only seems to be if I use the 'X' in the top right.

    2, Why is the Change Event not working when exiting the application, but works fine when you change something in the list box? Has it to do with the fact the Change Event is recorded on Sheet2 object?

    Please Login or Register  to view this content.
    hoping this is simple, as I'm a newbie to VBA.

    Thanks.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    How are you populating the listbox?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    04-17-2014
    Location
    Ireland
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Exiting Excel fires Change Event on ListBox

    Hi Norie,

    I'm using a Combo box to determine which Range is used to populate the ListFillRange on the Listbox.

  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: Exiting Excel fires Change Event on ListBox

    Are the ranges you use for ListFillRanges dynamic named ranges?

    If thet are they might be being recalculated when you exit the workbook, and that could be what's triggering the change event.

  5. #5
    Registered User
    Join Date
    04-17-2014
    Location
    Ireland
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Exiting Excel fires Change Event on ListBox

    Yes, they are dynamic named ranges. So if we assume that's what's causing the change event to trigger, any idea why it is failing (only when exiting application)?

  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: Exiting Excel fires Change Event on ListBox

    Not sure why you get the error when trying to clear contents.

    Can you upload an example workbook?

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

  7. #7
    Registered User
    Join Date
    04-17-2014
    Location
    Ireland
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Exiting Excel fires Change Event on ListBox

    File attached.
    Attached Files Attached Files

  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: Exiting Excel fires Change Event on ListBox

    This is weird, if I open the workbook and the close it again there's no error, if I open the workbook, open the VBE, close the VBE and then close the workbook I get the error.

    In the attached I've changed things a bit from the original, mainly using List to populate the listboxes instead of ListFillRange and now I don't seem to get the error.

    Can you give it a try?

    By the way, and this maybe a stupid question, but why are you duplicating Sheet2 in a userform (or is it the other way round)?

  9. #9
    Registered User
    Join Date
    04-17-2014
    Location
    Ireland
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Exiting Excel fires Change Event on ListBox

    I was originally going to complete this using a userform but changed my mind half way through!

    This is very strange, I've noticed that if I have another random workbook open at the same time, I don't get the error, but if it's the only workbook open then the error appears. The error seems to trigger when the entire application is closed at the same time as the workbook.

    Using your revised workbook, I seem to be getting an error when changing the combo box value...Method 'Range of object'_Worksheet' failed...looks to be linked to the using of the .Link to populate the listboxes.

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

    Re: Exiting Excel fires Change Event on ListBox

    That sounds more like a problem with a named range, have you checked them out?

    By the way, what's .Link?

  11. #11
    Registered User
    Join Date
    04-17-2014
    Location
    Ireland
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Exiting Excel fires Change Event on ListBox

    Sorry, that was a typo. meant to be .List not .Link.

    I'll check the named ranges to see if there is any issues there.

    Thanks for your assistance with this.

+ 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] DblClick event on listbox crashes Excel when I move the listbox as a result of the event
    By feanturi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-22-2022, 11:38 AM
  2. [SOLVED] Click event fires but doesnt work under initialze procedure
    By kmakjop in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-19-2014, 02:40 PM
  3. [SOLVED] listbox change event won't trigger when listbox is updated
    By Highlander777 in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 06-01-2013, 09:03 AM
  4. [SOLVED] Workbook_BeforeClose event fires twice when Excel itself is closing
    By blackworx in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-19-2012, 05:17 AM
  5. Workbook_beforeclose event fires before exit button
    By rajgud1234 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-24-2009, 08:09 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