简体   繁体   English

Excel 公式循环遍历一个范围

[英]Excel Formula to loop through a range

I am looking for an excel formula not VBA I can do it with VBA but there is a reason I do not want to use VBA.我正在寻找一个 excel 公式而不是 VBA 我可以用 VBA 做到这一点,但我不想使用 VBA 是有原因的

For example I have 1 column and 6 rows as per below.例如,我有 1 列和 6 行,如下所示。 I want to specify a number in an index to bring back the value.我想在索引中指定一个数字以恢复该值。

Row

  1. Apple苹果
  2. Orange橙子
  3. Banana香蕉
  4. Strawberry草莓
  5. Grape葡萄
  6. Kiwi猕猴桃

I would like the formula to start at 1 and then count how ever many rows I ask it to and go back to 1 after it gets to 6我希望公式从 1 开始,然后计算我要求它的行数,go 在它达到 6 后回到 1

So for example if I did =INDEX(A1:A6,9) then the result would be Banana OR if I did =INDEX(A1:A6, 18) the result would be Kiwi.因此,例如,如果我执行 =INDEX(A1:A6,9) 那么结果将是 Banana 或者如果我执行 =INDEX(A1:A6, 18) 结果将是 Kiwi。

I have tried all sorts to get it to work using index but it is just not working, every time I use a number outside the range it cannot be resolve.我已经尝试了各种方法让它使用索引来工作,但它只是不起作用,每次我使用超出范围的数字时,它都无法解决。

Using MOD :使用MOD

=INDEX(A1:A6,IF(MOD(9,6)=0,6,MOD(9,6)))

在此处输入图像描述

Other variations:其他变体:

=INDEX(A1:A6,IF(MOD(9,6),MOD(9,6),6))
=INDEX(A1:A6,MOD(9-1,6)+1)
=INDEX(A1:A6,MOD(18,6)+6*NOT(MOD(18,6)))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM