Hello i'm trying this code to take a range as input and to display some other values in the worksheet. The parametre of the addtwo function is variant, the first value of TableOfValues is the total number of values in the table. For example what I do: I select cells("B1" to "B5") type my addtwo(A1:A5) the cells for which i want the result are cells"A1" to "A5", in cell "A1" I have 5 (5 cells in the table) I try to display them in cells("B1" to "B5") using ctrl+shift
Function addtwo(ParamArray TableOfValues() As Variant) As Variant
Dim UResult() As Double
'table that would be passed to addtwo
ReDim UResult(TableOfValues(0)) As Double
'TableOfValues(0) contains the length of the table
UResult(0) = TableOfValues(0)
For i = 1 To 2 * TableOfValues(0)
UResult(i) = TableOfValues(i) + 2
Next
addtwo = UResult
End Function