I have created a Userform that lets the user pick a worksheet from a list of open worksheets. I need this Userform in various places of my macro, for various purposes; for example, to specify the worksheet containing “sales” data, and to specify the worksheet containing “stock” data. The objects wsSales and wsStock should point to the appropriate worksheets, so that my macro can later work on these.
How can I give each instance of my Userform a different behavior? One instance should set wsSales to the user-selected worksheet, the other instance should set wsStock to the user-selected worksheet.
I have thought about putting several “OK” buttons on my Useform, and making only one visible per instance. Each OK button would have different code. But that’s not very elegant, because I would have to put as much “OK” buttons as there are possible uses for my Userform and it would become quite a mess in more complex situations. So, ideally, I would use a property of my Userform as a pointer to either wsSales or wsStock, but I’ve read that pointers don’t exist in VBA. Then, what’s the best way to have two instances of a Userform behave differently?
Are you actually declaring variables as instances of the userform? If not, you should. You might want to look at this post: yoursumbuddy.com/a-flexible-vba-chooser-form.