this was posted here a while back and offers a probable solution
see attached workbook for multiple controls run by class
In Userform
Option Explicit
Dim handlers As Collection
Private Sub UserForm_Initialize()
Dim x As Long
Dim y As Long
Dim btn As MSForms.CommandButton
Dim handler As ButtonHandler
Const width = 40
Const height = 30
Const Space = 5
Const lblHeight = 15
Me.width = (6 * width) + (4.5 * Space)
Me.height = (6 * height) + (2 * Space)
Set handlers = New Collection
For x = 1 To 5
For y = 1 To 6
Set btn = Me.Controls.Add("Forms.CommandButton.1")
Set handler = New ButtonHandler
Set handler.CommandButton = btn
handlers.Add handler
With btn
.height = height
.width = width
.Top = ((x * height) - height) + Space
.Left = ((y * width) - width) + Space
.Caption = "R" & x & "C" & y
End With
Next y
Next x
End Sub
in class module called button handler
Option Explicit
Public WithEvents CommandButton As MSForms.CommandButton
Private Sub CommandButton_Click()
MsgBox CommandButton.Caption & " was clicked"
End Sub
Bookmarks