BP_
BP_

Reputation: 2647

How to call a function with arguments, return from the function and assign what was returned to a variable?

This is what I was trying:

Calling the function from the module:

LastWorkingDay = IsBusinessDay(Yesterday)

Function:

Public Function IsBusinessDay(Yesterday As Variant) As Date

...

InterestingVariable = #20/02/2014#

End Function

I would like to return InterestingVariable and assign it to LastWorkingDay. There is no return statement in VBA, so how do you decide what you want to return. Or, how do you call a function to return a particular variable calculated in the function In my case it would "InterestingVariable".

Upvotes: 1

Views: 95

Answers (2)

user2140173
user2140173

Reputation:

return in VBA is the function name and = <return value>

so for example

Public Function MyFunction() as String
    MyFunction = "returned from MyFunction"
End Function

so MsgBox MyFunction returns a String returned from MyFunction

Upvotes: 2

MLDev
MLDev

Reputation: 1277

add this line to your function

IsBusinessDay = InterestingVariable 

Upvotes: 1

Related Questions