Hi All,
I have a VBA UserForm GUI and one of the controls is a multi-select, tick-box option ListBox. The items in the listbox are either category types ("Domain1", "Domain2", etc) or items that fall in said categories ("Indicator1", etc..).
I have written a macro to handle the different ways in which the options can be checked - for instance, if a category type is checked, all of the elements in that category will also be checked. Additionally, there is cross-category grouping such that once a list item has been selected, only items from the same group (which could be in a different category) are displayed.
My problem is that my macro seems to work as I would like but as soon as the code returns to the ListBox_Change declaration that calls it, it seems to change the items in the list, despite there being no code instructing it to do so. This doesn't happen in breakpoint mode.
I attach an example workbook - if you launch the UserForm and select DOMAIN1, it correctly checks the members of the DOMAIN1 category and removes from the list all items that aren't in Group 1. The problem arises if you then try to make any further changes to the list: for instance, if you then uncheck Indicator1, it doesn't change anything - it briefly flashes to the correct list but then reverts to the previous list. However, if you put a breakpoint in after the macro is called (in the ListBox_Change declaration) there is no problem.
It seems that the ListBox_Change declaration itself is making changes to the list and I don't understand why - does anyone have any ideas?
FYI I have tried the following with no improvement:
- Looped through the list and deselected all items before clearing
- Tried using the MouseUp event (this had similar problems)
- Putting a Sleep in at the end of the macro in case there was some lag
- Adding in DoEvents everywhere
PS: I know that my macro is not perfect, but I don't think that it is the problem per se - I won't be able to finish refining the code until I can effectively test it. My suspicion is that it has something to do with programmatically selecting/deselecting list items but I can't be sure.
Bookmarks