ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Passing Paramiters and UDF Question (https://www.excelbanter.com/excel-programming/415811-passing-paramiters-udf-question.html)

Office_Novice

Passing Paramiters and UDF Question
 
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


Bernie Deitrick

Passing Paramiters and UDF Question
 
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


"Office_Novice" wrote in message
...
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





All times are GMT +1. The time now is 12:31 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com