简体   繁体   English

Excel公式中的动态参考

[英]Dynamic reference in excel formula

I have the following array formula which works for what I want to do but I'm trying to change the formula when a user selects a value. 我有以下适用于我想做的事情的数组公式,但是当用户选择一个值时,我试图更改公式。

=INDEX($A$2:$B$70,SMALL(IF($A$2:$B$70=$A$121,ROW($A$2:$B$70)),ROW(1:1))-1,1)

It's used for a monthly report and the user will choose from a drop down the day of the month, eg 1,2,3 - 31. 它用于月度报告,用户将在每月的下拉列表中进行选择,例如1,2,3-31。

So if the user selects 1 from the drop down menu I want the formula to use the above formula. 因此,如果用户从下拉菜单中选择1,则我希望该公式使用上述公式。 If they select 2 for example I want the formula to move over a column so it would change to 例如,如果他们选择2,则我希望公式在列上移动,以便将其更改为

=INDEX($A$2:$C$70,SMALL(IF($A$2:$C$70=$A$121,ROW($A$2:$C$70)),ROW(1:1))-1,1)

and so on moving over a column at a time. 等等,一次移到一列上。

It this possible at all or can it even be done without VBA? 完全有可能做到这一点,或者甚至可以在没有VBA的情况下完成?

I have an example of what I want done on the following link https://docs.google.com/spreadsheets/d/1MDOzoQxYLgW-UOyljZsMwSu8zyAB7O2k1V-bTNP5_F0/edit?usp=sharing 我在以下链接上有我想做的事的示例https://docs.google.com/spreadsheets/d/1MDOzoQxYLgg-UOyljZsMwSu8zyAB7O2k1V-bTNP5_F0/edit?usp=sharing

All the data is on the first tab called staff. 所有数据都在第一个称为“人员”的选项卡上。 Each employee has a row and the duty assigned under the corresponding day column. 每个员工都有一行,并在相应的天列下分配了职责。 On the Roster tab it summarises each day. 在“名册”选项卡上,它每天汇总。 So what I am trying to get to happen is when you choose the day of the month (or preferably the actual date) the sheet changes to reflect the data. 因此,我试图实现的是当您选择工作表更改为反映数据的月份(最好是实际日期)时。

At the moment the code I have working does for just Day 1 because the column references are coded into the formula. 目前,我正在使用的代码仅适用于第一天,因为列引用已编码到公式中。 I was hoping to somehow choose 6 for example from the drop down and then the formula will map chosen day to the corresponding range in the raw data and update the formula and change the formula from Staff!$A$2:$B$68 to Staff!$A$2:$G$68 . 我希望以某种方式从下拉列表中选择6,例如,该公式会将所选的日期映射到原始数据中的相应范围,并更新公式并将公式从Staff!$A$2:$B$68 to Staff!$A$2:$G$68

If the formula finds no more entries if shows #NUM! 如果公式找不到更多条目,则显示#NUM! but I intended to use the function ISERROR() to replace #NUM! 但我打算使用函数ISERROR()代替#NUM! with "". 与“”。

This is what I'm trying to achieve it if makes sense? 这是我要实现的目标,如果有道理?

There are a few issues here/ You are returning the value from column A so the first range can be $A$2:$A$70 and that means you don't need the 1 to specify the column_num . 这里有一些问题/您正在从A列返回值,因此第一个范围可以是$A$2:$A$70 ,这意味着您不需要1来指定column_num The IF statement was covering A2:C70 when you really only want either B2:70 or C2:C70 depending on the 1 or 2. 当您实际上只希望B2:70或C2:C70取决于1或2时, IF语句将覆盖A2:C70。

Assuming that A122 has either a 1 or 2 in it then, 假设A122中有1或2,

=INDEX($A$2:$A$70, SMALL(IF(INDEX($B$2:$C$70, 0, $A$122) = $A$121, ROW($1:$69)), ROW(1:1)))

Standard non-array alternative, 标准非阵列替代方案

=INDEX($A$2:$A$70, SMALL(INDEX(ROW($1:$69)+(INDEX($B$2:$C$70, 0, $A$122) <> $A$121)*1E+99,, ), ROW(1:1)))

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

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