View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
NickHK NickHK is offline
external usenet poster
 
Posts: 4,391
Default Returning a value forom a Module to a Userform

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

"CSUS_CE_Student" wrote in message
...
Close, but to a Sub, not a function.
How would i do that from a UserForm and a Sub


"NickHK" wrote:

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

"CSUS_CE_Student" wrote in

message
...
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?