Returning a value forom a Module to a Userform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to make a userform to return some data from the spreadsheet after
the analysis is done in a public Sub. How do I call the variable from the
public module to the userform?
 
You mean something like this ?

'<Userform code>
Private Sub CommandButton1_Click()
MsgBox MyFunction(20, 10)
End Sub
'</Userform code>

'<Module code>
Public Function MyFunction(Arg1 As Long, Arg2 As Long) As Long
MyFunction = Arg1 * Arg2
End Function

'</Module code>

NickHK
 
You can't return a value from a sub*; that's what a function is for.
Why do you not want a function ?

* Well, you can pass an argument ByRef, the default in VB/VBA, and change
its value in the sub.

NickHK
 
Back
Top