I want the function to take a range of cells as an argument and return its product. Assume the following value for cells:
A1=5
A2=2
A3=3
Call by function Multiply
. =Multiply(A1:A3)
will return 30 (= 5 × 2 × 3).
What is the code for this? I'm just trying to get familiar with the syntax, and that will help a lot.
Edit: found out:
Function multiply(rng As Range)
multiplied = 1
For Each cell In rng
multiplied = multiplied * cell.Value
Next
multiply = multiplied
End Function
source
share