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.
 
Rorya, I am going to switch to your suggested method of populating the listbox; it will probably take me a while get everything sorted in order to confirm if that resolves my particular problem.

Haha Hermanito, I actually did close Excel and reboot my PC earlier hoping that the issue would just resolve itself.:biggrin:
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Yes, Row Source is definitely the issue. Its going to be a pain to rework the populating of the list box (my list box has multiple columns which has proven to be difficult ... probably why i went with Row Source when i originally set it up) but eliminating row source will solve my problem.

Thank you both for your help.
 
Upvote 0
For multicolumn lists, I prefer to use ListView instead of ListBox. It has more flexibility I think...

Good luck with the refactoring!
 
Upvote 0
Multiple columns are just as easy with List - just assign the whole range to it.
 
Upvote 0
My list box has 3 columns. My range is continuous and also consists of 3 columns (variable number of rows)... yet the following assignment kicks back an error:

Code:
UserForm1.ListBox1.List = Worksheets("MyWorksheet").Range("MyRange").Value

Specific Error: Run-time error '70' Permission denied.

Am I approaching this wrong... are there any obv errors in the above code?

Thanks
 
Upvote 0
Do you still have the Rowsource property set?
 
Upvote 0
argh... yes, i was inadvertently setting the rowsource programmatically and then trying to use the .List assignment. I found and eliminated the method that was setting the rowsource property and all seems to be working smoothly. Thanks again.:cool:
 
Upvote 0
I need to grab values from the columns individually. The method below was working when using row source property, but now returns error "Could not get list property Invalid argument"

Code:
myItem = ListBox1.List(ListBox1.ListIndex, 2)

If I remove the 2, or replace the 2 with zero, I get no error. However it then returns the value located in the first column of the first row (.listindex = 0). Also this is being called from the click event which is triggered by

Code:
UserForm1.ListBox1.List = rngFiltered.Value

where rngFiltered is a continuous range with three columns and a variable number of rows. Is there a better way of accessing values by column?
 
Upvote 0
Sorry... Jumped the gun on that last post. rngFiltered was only being set equal to a one column range. Issue resolves when rngFiltered is properly set.
 
Upvote 0

Forum statistics

Threads
1,224,550
Messages
6,179,462
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