Friday, 13 July 2012

Excel VBA function on value in a range from called cell

In a cell you can refer to an range and the corresponding entry in the array is used as an input.
E.g. with with a1 to a6 filled with 1 to 6 and is named test_range and b2 has the formula = test_range + 1
b2 => 2
However if you put the range into a vba worksheet function, the whole range is passed.
and you need to select the specific value
e.g.
public function add_one (src_range) as variant
add_one = src_range.Cells(1 + Application.ThisCell.Row - src_range.Row, 1).Value
end function