Hi again Keeballah,
Take a look at the attached workbook and see what you think.
I've encapsulated the code as much as possible. This approach ensures that code in a standard CodeModule "knows" nothing about the layout, controls etc. of a UserForm. Similarly (although it doesn't apply in this example), the code in a UserForm Class CodeModule "knows" nothing about workbooks, worksheets, ranges etc.
Note that the ONLY parameter passed to the UserForm is the number of button rows to be created. Note also that the UserForm does not use an initialisation routine - it waits until it has been "told" how many button rows should be created and creates them only at that stage.
Also, a reference to the clicked button is passed "all the way back" to the routine which displays the UserForm. At that stage the value of the Tag (or indeed any other) property of the clicked button can be retrieved.
The workbook uses the following code in a standard VBA CodeModule:
the following code in the VBA CodeModule for the UserForm:
and the following code in the VBA CodeModule for the CommandButton Class:
The highlighted values may be altered to suit your own button layout requirements.
The "ButtonClicked" (Get) property of the UserForm allows it to communicate with the routine which displays the UserForm.
The "ButtonClicked" (Let) property of the UserForm allows the CommandButton Class Module to communicate with the UserForm.
Hope this helps - as before, please let me know how you get on.
Regards,
Greg M
Bookmarks