Home » excel » excel – Reverse a 1d array output from a function (or get the last value), without VBA?

excel – Reverse a 1d array output from a function (or get the last value), without VBA?

Posted by: admin May 14, 2020 Leave a comment

Questions:

Suppose I have a UDF MyFunc() which is too costly to call more than once, MyFunc() returns an array. By default, if applied to a single cell then the first value in the array is used. I want the last value of the array.

So, is it possible to:

  • (a) reverse the array so that the last value is used, or

  • (b) just grab the last value directly?

How to&Answers:

You can use INDEX to return a certain position

If you know the position you want you could use

=INDEX(Myfunct(),2)

for the second position etc

For the last position of unknown size

=INDEX(Myfunct(),COUNTA(Myfunct()))

second last

=INDEX(Myfunct(),COUNTA(Myfunct())-1)