ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Format when sending a range as parameter to a custom function (https://www.excelbanter.com/excel-programming/347068-format-when-sending-range-parameter-custom-function.html)

George Furnell

Format when sending a range as parameter to a custom function
 
Hello,

I created a custom functiom for which I need to send a range (A1:A5), that I
will loop throu in my function.

Please indicate what the funtion definition will looklike, ie how do I
specify that it will receive a range in that format? I do have the code that
will loop through the cells.

Kind regards

George

Jim Thomlinson[_4_]

Format when sending a range as parameter to a custom function
 
Something like this... (hard to tell from your question)

Public Sub SendRange()
Dim dblAmount As Double

dblAmount = RecieveRange(Sheets("Sheet1").Range("A1:A5"))
MsgBox "The total is " & dblAmount
End Sub

Public Function RecieveRange(ByVal MyRange As Range) As Double
Dim rng As Range
Dim dblTotal As Double

For Each rng In MyRange
dblTotal = dblTotal + rng.Value
Next rng
RecieveRange = dblTotal
End Function

--
HTH...

Jim Thomlinson


"George Furnell" wrote:

Hello,

I created a custom functiom for which I need to send a range (A1:A5), that I
will loop throu in my function.

Please indicate what the funtion definition will looklike, ie how do I
specify that it will receive a range in that format? I do have the code that
will loop through the cells.

Kind regards

George


George Furnell[_2_]

Format when sending a range as parameter to a custom function
 
Thank you so much.
Kind regards

George


All times are GMT +1. The time now is 06:17 AM.

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