I am new to the board. I have a module in VBA for Excel and an associated user form with 4 CommandButtons. I call the user form with frmSelect.Show
. The user is to pick on 1 of the 4 Command buttons and then a value is assigned to a variable that I want to pass to the module. This way I can tell which CommandButton was activated. I cannot seem to figure out how to pass a variable as the variable always comes back to the module as a null (0).
This is the module code:
Sub BumpGenerator()
Dim Pattern As Integer
frmSelect.Show
If Pattern = 1 then
Do some stuff
End If
If Pattern = 2 then
Do some other stuff
End If
If Pattern = 3 then
Do some other stuff
End If
If Pattern = 4 then
Do this stuff
End If
End Sub
This is the code in the user form:
Private Sub CommandButton1_Click()
Pattern = 1
frmSelect.Hide
End Sub
Private Sub CommandButton2_Click()
Pattern = 2
frmSelect.Hide
End Sub
Private Sub CommandButton3_Click()
Pattern = 3
frmSelect.Hide
End Sub
Private Sub CommandButton4_Click()
Pattern = 4
frmSelect.Hide
End Sub
I have tried using:
'Public Pattern As Integer' above my module
Passing Pattern as a variable using 'BumpGenerator(Pattern As Integer)'
Using 'Call BumpGenerator(Pattern)' in the user form
Using 'BumpGenerator Value:=Pattern'
but none of those options changed my null.
Thank you for any replies