UserForm Event Fires Randomly

Boswell

Board Regular
Joined
Jun 18, 2010
Messages
224
I have a workbook with a rather complicated series of user forms. One of the forms consists of a list box with an associated click event that fires randomly (or for reasons i do not understand). I have tirelessly stepped through the code to verify that the list box is *not* being "clicked" or altered programmatically when it is firing.

The list box click event tends to fire when a range on a worksheet is calculated. Additionally, it fires 20+ times upon the user form initialization event. I set the contents of the list box via row source and even if there are only a few items added upon initialization the list box click event still fires 20+ times.

Is anyone familiar with this problem.. are there some coding best practices I am overlooking? :confused: The code is too circuitous to post; however, I am an experienced VBA programmer and have ruled out any obvious issues (such as nested events that are calling each other back and forth)

Any suggestions would be appreciated.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
when the sheet is recalculating, does this include the cells you use for rowsource of the listbox? Then each recalculate might trigger the change event, even if the value does not really change. Not sure here, but it must be something like that if you ruled out other things...
 
Upvote 0
Thanks for your reply Hermanito. That is a very good thought I had not considered. I do not think that this is the issue, however I am going to step through the code again to be absolutely sure.
 
Upvote 0
If you have controls bound to the worksheet, as Hermanito said, that is almost certainly the cause. It's one reason why I never bind anything directly to a worksheet (either in or out).
 
Upvote 0
I tried to reproduce this behaviour with a simple setup:
- userform with listbox bound to a range
- bound range contains formulas
- other cell contains counter of how many times the listbox change event gets called

the listbox on the (modeless) userform gets updated when I recalculate and the formula results change, but the listbox change event does NOT fire in my case...

I did not expect that actually...
 
Upvote 0
Previous test was with the userform shown, but without selecting anything in the list.
When I have a listitem selected, and then change values in the bound range, the change event gets called twice
Then I thought, maybe when multiselect is enabled and I select everything in the list, the change event gets called twice for each element, but that's not happening. In that case, it doesn't fire at all again...:eeek:
 
Upvote 0
For a multiselect listbox, the Value property no longer returns anything, so it doesn't change.
 
Upvote 0
I too have not been able to slow my click events by altering my code, but have a mountain of it to go through to weed out all possible instances where I am calculating the range containing the row source. I am warming up to the idea that this is indeed my issue...

Note that My issue is with a click event (not a change event).
 
Upvote 0
Personally, I would remove the rowsource and populate the list in code using:
Code:
listbox1.list = sheets("blah").Range("yadda").Value
 
Upvote 0
Ah, I totally overlooked that you were talking about the click event. That makes it even weirder I think...

Have you tried closing and reopening Excel?
If that doesn't work, rebooting the pc?
(just stating the first two options any helpdesk would provide :biggrin:)
 
Upvote 0

Forum statistics

Threads
1,224,544
Messages
6,179,430
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top