Format when sending a range as parameter to a custom function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 

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

Back
Top