Using Range inputs in functions

  • Thread starter Thread starter Curare
  • Start date Start date
C

Curare

How can I get the values inputed into a function from a range of values
Below is an example of the values used in the worksheets.

A
1 12
2 15
3 36
4 25
5 18
6 23

For a follow up question, does the range selection always have to b
in this format, or can I also use the format below:

A B C D E F
1 12 15 36 25 18 23

If yes, how would the function determine between formats
 
Hi
one way (without much error testing, etc):
Function foo_sum (rng as range)
Dim cell as range
Dim ret_value as double
for each cell in rng
if IsNumeric(cell.value) then
ret_value = ret_value + cell.value
end if
next
foo_sum = ret_value
end function

And yes you can use a different range layout :-)
 
Curare,

For Each cell in rng
'do something
Next cell

Either works. If you use Selection, it doesn't need to differentiate.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Back
Top