Rotate an array index?

gifariz

Board Regular
Joined
May 2, 2021
Messages
128
Office Version
  1. 365
Platform
  1. Windows
Suppose I have an array X = {"A";"B";"C"}
I want to rotate the index by an integer i, suppose i = 1, so that Y = Rotate(X,i) = {"C";"A";"B"}
Is there excel function to do this?
What I do now is Y = LET(X,H18#,i,H16,n,COUNTA(X),ix,SEQUENCE( n)-H16,INDEX(X,IF(ix<1,ix+n,ix)))
which is quite mothful. Thanks
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
You mean like this?
Code:
Y = Application.Index(X, WorksheetFunction.Sequence(UBound(X), , UBound(X), -1), 0)
 
Upvote 0
Try:
Book1
ABCD
1ArrayiResult
2A2B
3BC
4CA
Sheet3
Cell Formulas
RangeFormula
A2:A4A2= {"A";"B";"C"}
D2:D4D2=LET(r,ROWS(A2#),INDEX(A2#,MOD(SEQUENCE(r)-1-B2,r)+1))
Dynamic array formulas.
 
Upvote 0
Solution
Edit: Y = LAMBDA(X,i,LET(n,COUNTA(X),seq,SEQUENCE( n),ix,seq-i,INDEX(X,IFS(i=0,seq,i>0,IF(ix<1,ix+n,ix),i<0,IF(ix>n,ix-n,ix)))))
 
Upvote 0
This looks close. But when I try A2={"A";"B";"C";"D"}, and B2=-1, it returns incorrect result. Maybe it has something to do with MOD divisor?

Edit: oh great, you updated your answer. It works great now. Thank you!
 
Upvote 0

Forum statistics

Threads
1,226,462
Messages
6,191,177
Members
453,644
Latest member
karlpravin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top