So there are a bunch of ways to reverse a list to turn it into a new list, using helper columns. I've written some code that does use helper columns to reverse a list and then use it.
I'm wondering how I would reverse a list without using a helper column for use in a sumproduct - for example,
=sumproduct(Reverse(A1:A3),B1:B3)
This array formula will reverse the order of a vertical array:
Also, this reverses a horizontal array:
EDIT
More generally, to vertically flip a matrix instead of just an array (which is just a one-dimensional matrix), use this array formula: (e.g. for range
A1:D2
)And to horizontally flip a matrix, use this:
And a bonus... to flip a matrix horizontally and vertically in one shot (i.e. rotate it 180 degrees):
Actually this last one here could more generally be used to flip either a horizontal or vertical array.
For what it's worth, here's another completely different method to reverse an array. (I'm posting this as a separate answer just because it is apples and oranges to the other answer I already provided.)
Instead of reversing the order of the array by reversing the indexing, it is also possible to use matrix multiplication (
MMULT
) to accomplish this.If your data in
A1:A3
is{1;3;5}
(for example) then the following matrix multiplication effectively reverses this array:In order to generate that matrix of
1
's and0
's above, you can do this (line break added for readability):So in the end, the formula to reverse this array would be:
This same line of thinking can be used to reverse a horizontal array. For example if
A1:C1
is{1,3,5}
, then:Note how the matrix of
1
's and0
's is the second argument this time instead of the first argument.Using the same general line of reasoning, you can get to this formula to reverse a horizontal array.
This method has two major disadvantages as compared two the
N(IF(...))
solution, namely:It's way longer.
It only works for numbers since
MMULT
requires numbers, but the other method works if the cells contain anything (e.g. text).I was using this solution to reverse arrays without helper columns until just recently when I learned about the
N(IF(...))
alternative.This will do what you are asking:
To make a little more dynamic you can use this array formula:
Being an array formula, it needs to be confirmed with Ctrl-Shift-Enter, instead of Enter when exiting Edit mode.
Actually you can make the formula in your Question work (with a small UDF()):
Pick a cell and enter:
with this in a standard module: