Passing Paramiters and UDF Question

O

Office_Novice

Greetings, I have a function that adds two ranges then subtracts Range B from
Range A giving me "N" I would like to know how to modify the following to be
able to pass N back into a sub procedure on a userform.

Function GetBalances()
Dim x As Long, y As Long, N As Long
Dim ARange As Range, BRange As Range

Set ARange = Range("A:A")
Set BRange = Range("B:B")

x = WorksheetFunction.Sum(ARange)
y = WorksheetFunction.Sum(BRange)
N = x - y
Debug.Print N
End Function
 
B

Bernie Deitrick

Sub Test()
MsgBox GetBalances
End Sub

Function GetBalances() As Long
Dim x As Long, y As Long, N As Long
Dim ARange As Range, BRange As Range

Set ARange = Range("A:A")
Set BRange = Range("B:B")

x = WorksheetFunction.Sum(ARange)
y = WorksheetFunction.Sum(BRange)
N = x - y
GetBalances = N
End Function


HTH,
Bernie
MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top