动态设置 MAX() 或 MIN() 函数的范围
Dynamically setting a range for MAX() or MIN() functions
我正在制作甘特图电子表格并尝试完成不可能的工作(看起来是这样)
基本上我想要实现的是,U 和 W 列中的日期将根据 G 列值(行类型)为最小或最大函数动态设置范围,因此两个 [=38] 之间的所有内容=](主要部分)和两个 S(部分)之间将被定义为一个范围。
问题是行类型由用户设置,行数可以从 1 到第 N,所以固定的 MIN 或 MAX 公式并不是一个真正的选项
开始范围很容易 - 基本 IF(G13="PS",...,...)
我需要帮助的困难部分是获取下一个 S 或 PS 类型之前的最后一个范围行。
请参阅下面的示例范围。
目前取得的成绩:=MAX(IF(tipas="PS",INDIRECT("U" & ROW(id)),IF(tipas="S",INDIRECT("U" & ROW(id)),"")):U17)
完整单元格公式:
=IFERROR(IF(AND(tipas<>"",tipas="PS"),MAX(INDIRECT("U" & ROW(id):U17),
IF(AND(tipas<>"",tipas="S"),MAX(INDIRECT("U" & ROW(id):U17),
'formulas to get the date for other types'
IF(plan.pradzia<>"",plano.pabaigos.skaic,IF(plan.pabaiga<>"",plan.pabaiga,IF(eilNr<>"",
IF(darbo.priklausomumas="PrPb",prpb.skaic,IF(darbo.priklausomumas="PbPb",pbpb.skaic,plano.pabaigos.skaic)),""))))),"")
tipas is a nemed range for G column
如何根据 G 列值动态获取 U17 值?
由于我不知道哪些单元格可用,我们假设范围 HA:HF 可用。相应地放置这些公式:
ADDRESS
OUTCOME DESCRIPTION
FORMULA
HA13
Row of any PS cell.
=IF($G13="PS",ROW($G13),"")
HB13
Row of any PS or S cell.
=IF(OR($G13="PS",$G13="S"),ROW($G13),"")
HC13
Address of the range for the PS section in the U column (reported on the proper PS row).
=IF($G13="PS",IF(OR(OFFSET($G13,1,0)="PS",OFFSET($G13,1,0)=""),"","U"&MAX(HA:HA13)+1&":U"&IF(MIN(INDIRECT(CELL("address",OFFSET(HA13,1,0))&":"&ADDRESS(ROWS(HA:HA),CELL("col",HA:HA),1,1)))-1=0,MATCH(TRUE,INDEX(INDIRECT(CELL("address",OFFSET($G13,1,0))&":"&ADDRESS(ROWS($G:$G),CELL("col",$G:$G),1,1))="",0),FALSE)+ROW($G13),MIN(INDIRECT(CELL("address",OFFSET(HA13,1,0))&":"&ADDRESS(ROWS(HA:HA),CELL("col",HA:HA),1,1)))-1)),"")
HD13
Address of the range for the S section in the U column (reported on the proper S row).
=IF($G13="S",IF(OR(OFFSET($G13,1,0)="PS",OFFSET($G13,1,0)="S",OFFSET($G13,1,0)=""),"","U"&MAX(HB:HB13)+1&":U"&IF(MIN(INDIRECT(CELL("address",OFFSET(HB13,1,0))&":"&ADDRESS(ROWS(HB:HB),CELL("col",HB:HB),1,1)))-1=0,MATCH(TRUE,INDEX(INDIRECT(CELL("address",OFFSET($G13,1,0))&":"&ADDRESS(ROWS($G:$G),CELL("col",$G:$G),1,1))="",0),FALSE)+ROW($G13),MIN(INDIRECT(CELL("address",OFFSET(HB13,1,0))&":"&ADDRESS(ROWS(HB:HB),CELL("col",HB:HB),1,1)))-1)),"")
HE13
Address of the range for the PS section in the W column (reported on the proper PS row).
=IF($G13="PS",IF(OR(OFFSET($G13,1,0)="PS",OFFSET($G13,1,0)=""),"","W"&MAX(HA:HA13)+1&":W"&IF(MIN(INDIRECT(CELL("address",OFFSET(HA13,1,0))&":"&ADDRESS(ROWS(HA:HA),CELL("col",HA:HA),1,1)))-1=0,MATCH(TRUE,INDEX(INDIRECT(CELL("address",OFFSET($G13,1,0))&":"&ADDRESS(ROWS($G:$G),CELL("col",$G:$G),1,1))="",0),FALSE)+ROW($G13),MIN(INDIRECT(CELL("address",OFFSET(HA13,1,0))&":"&ADDRESS(ROWS(HA:HA),CELL("col",HA:HA),1,1)))-1)),"")
HF13
Address of the range for the S section in the W column (reported on the proper S row).
=IF($G13="S",IF(OR(OFFSET($G13,1,0)="PS",OFFSET($G13,1,0)="S",OFFSET($G13,1,0)=""),"","W"&MAX(HB:HB13)+1&":W"&IF(MIN(INDIRECT(CELL("address",OFFSET(HB13,1,0))&":"&ADDRESS(ROWS(HB:HB),CELL("col",HB:HB),1,1)))-1=0,MATCH(TRUE,INDEX(INDIRECT(CELL("address",OFFSET($G13,1,0))&":"&ADDRESS(ROWS($G:$G),CELL("col",$G:$G),1,1))="",0),FALSE)+ROW($G13),MIN(INDIRECT(CELL("address",OFFSET(HB13,1,0))&":"&ADDRESS(ROWS(HB:HB),CELL("col",HB:HB),1,1)))-1)),"")
然后拖动单元格以覆盖整个列表。您可以使用 INDIRECT 函数将地址集成到您的公式中。例如:
=MAX(INDIRECT(HC13))
或
=MAX(INDIRECT(IF($G13="PS",IF(OR(OFFSET($G13,1,0)="PS",OFFSET($G13,1,0)=""),"","U"&MAX(HA:HA13)+1&":U"&IF(MIN(INDIRECT(CELL("address",OFFSET(HA13,1,0))&":"&ADDRESS(ROWS(HA:HA),CELL("col",HA:HA),1,1)))-1=0,MATCH(TRUE,INDEX(INDIRECT(CELL("address",OFFSET($G13,1,0))&":"&ADDRESS(ROWS($G:$G),CELL("col",$G:$G),1,1))="",0),FALSE)+ROW($G13),MIN(INDIRECT(CELL("address",OFFSET(HA13,1,0))&":"&ADDRESS(ROWS(HA:HA),CELL("col",HA:HA),1,1)))-1)),"")))
我尝试过基于 AGGREGATE 的解决方案,但它似乎速度较慢并且可能需要更多列。这个解决方案应该更轻,但如果列表很长,它可能仍然太慢。在这种情况下,VBA 解决方案对于用户定义的函数可能更好。再一次,问题的标签是 excel
和 excel-formula
。如果需要,我可能会尝试用户定义的函数。
我正在制作甘特图电子表格并尝试完成不可能的工作(看起来是这样)
基本上我想要实现的是,U 和 W 列中的日期将根据 G 列值(行类型)为最小或最大函数动态设置范围,因此两个 [=38] 之间的所有内容=](主要部分)和两个 S(部分)之间将被定义为一个范围。
问题是行类型由用户设置,行数可以从 1 到第 N,所以固定的 MIN 或 MAX 公式并不是一个真正的选项
开始范围很容易 - 基本 IF(G13="PS",...,...)
我需要帮助的困难部分是获取下一个 S 或 PS 类型之前的最后一个范围行。
请参阅下面的示例范围。
目前取得的成绩:=MAX(IF(tipas="PS",INDIRECT("U" & ROW(id)),IF(tipas="S",INDIRECT("U" & ROW(id)),"")):U17)
完整单元格公式:
=IFERROR(IF(AND(tipas<>"",tipas="PS"),MAX(INDIRECT("U" & ROW(id):U17),
IF(AND(tipas<>"",tipas="S"),MAX(INDIRECT("U" & ROW(id):U17),
'formulas to get the date for other types'
IF(plan.pradzia<>"",plano.pabaigos.skaic,IF(plan.pabaiga<>"",plan.pabaiga,IF(eilNr<>"",
IF(darbo.priklausomumas="PrPb",prpb.skaic,IF(darbo.priklausomumas="PbPb",pbpb.skaic,plano.pabaigos.skaic)),""))))),"")
tipas is a nemed range for G column
如何根据 G 列值动态获取 U17 值?
由于我不知道哪些单元格可用,我们假设范围 HA:HF 可用。相应地放置这些公式:
ADDRESS | OUTCOME DESCRIPTION | FORMULA |
---|---|---|
HA13 | Row of any PS cell. | =IF($G13="PS",ROW($G13),"") |
HB13 | Row of any PS or S cell. | =IF(OR($G13="PS",$G13="S"),ROW($G13),"") |
HC13 | Address of the range for the PS section in the U column (reported on the proper PS row). | =IF($G13="PS",IF(OR(OFFSET($G13,1,0)="PS",OFFSET($G13,1,0)=""),"","U"&MAX(HA:HA13)+1&":U"&IF(MIN(INDIRECT(CELL("address",OFFSET(HA13,1,0))&":"&ADDRESS(ROWS(HA:HA),CELL("col",HA:HA),1,1)))-1=0,MATCH(TRUE,INDEX(INDIRECT(CELL("address",OFFSET($G13,1,0))&":"&ADDRESS(ROWS($G:$G),CELL("col",$G:$G),1,1))="",0),FALSE)+ROW($G13),MIN(INDIRECT(CELL("address",OFFSET(HA13,1,0))&":"&ADDRESS(ROWS(HA:HA),CELL("col",HA:HA),1,1)))-1)),"") |
HD13 | Address of the range for the S section in the U column (reported on the proper S row). | =IF($G13="S",IF(OR(OFFSET($G13,1,0)="PS",OFFSET($G13,1,0)="S",OFFSET($G13,1,0)=""),"","U"&MAX(HB:HB13)+1&":U"&IF(MIN(INDIRECT(CELL("address",OFFSET(HB13,1,0))&":"&ADDRESS(ROWS(HB:HB),CELL("col",HB:HB),1,1)))-1=0,MATCH(TRUE,INDEX(INDIRECT(CELL("address",OFFSET($G13,1,0))&":"&ADDRESS(ROWS($G:$G),CELL("col",$G:$G),1,1))="",0),FALSE)+ROW($G13),MIN(INDIRECT(CELL("address",OFFSET(HB13,1,0))&":"&ADDRESS(ROWS(HB:HB),CELL("col",HB:HB),1,1)))-1)),"") |
HE13 | Address of the range for the PS section in the W column (reported on the proper PS row). | =IF($G13="PS",IF(OR(OFFSET($G13,1,0)="PS",OFFSET($G13,1,0)=""),"","W"&MAX(HA:HA13)+1&":W"&IF(MIN(INDIRECT(CELL("address",OFFSET(HA13,1,0))&":"&ADDRESS(ROWS(HA:HA),CELL("col",HA:HA),1,1)))-1=0,MATCH(TRUE,INDEX(INDIRECT(CELL("address",OFFSET($G13,1,0))&":"&ADDRESS(ROWS($G:$G),CELL("col",$G:$G),1,1))="",0),FALSE)+ROW($G13),MIN(INDIRECT(CELL("address",OFFSET(HA13,1,0))&":"&ADDRESS(ROWS(HA:HA),CELL("col",HA:HA),1,1)))-1)),"") |
HF13 | Address of the range for the S section in the W column (reported on the proper S row). | =IF($G13="S",IF(OR(OFFSET($G13,1,0)="PS",OFFSET($G13,1,0)="S",OFFSET($G13,1,0)=""),"","W"&MAX(HB:HB13)+1&":W"&IF(MIN(INDIRECT(CELL("address",OFFSET(HB13,1,0))&":"&ADDRESS(ROWS(HB:HB),CELL("col",HB:HB),1,1)))-1=0,MATCH(TRUE,INDEX(INDIRECT(CELL("address",OFFSET($G13,1,0))&":"&ADDRESS(ROWS($G:$G),CELL("col",$G:$G),1,1))="",0),FALSE)+ROW($G13),MIN(INDIRECT(CELL("address",OFFSET(HB13,1,0))&":"&ADDRESS(ROWS(HB:HB),CELL("col",HB:HB),1,1)))-1)),"") |
然后拖动单元格以覆盖整个列表。您可以使用 INDIRECT 函数将地址集成到您的公式中。例如:
=MAX(INDIRECT(HC13))
或
=MAX(INDIRECT(IF($G13="PS",IF(OR(OFFSET($G13,1,0)="PS",OFFSET($G13,1,0)=""),"","U"&MAX(HA:HA13)+1&":U"&IF(MIN(INDIRECT(CELL("address",OFFSET(HA13,1,0))&":"&ADDRESS(ROWS(HA:HA),CELL("col",HA:HA),1,1)))-1=0,MATCH(TRUE,INDEX(INDIRECT(CELL("address",OFFSET($G13,1,0))&":"&ADDRESS(ROWS($G:$G),CELL("col",$G:$G),1,1))="",0),FALSE)+ROW($G13),MIN(INDIRECT(CELL("address",OFFSET(HA13,1,0))&":"&ADDRESS(ROWS(HA:HA),CELL("col",HA:HA),1,1)))-1)),"")))
我尝试过基于 AGGREGATE 的解决方案,但它似乎速度较慢并且可能需要更多列。这个解决方案应该更轻,但如果列表很长,它可能仍然太慢。在这种情况下,VBA 解决方案对于用户定义的函数可能更好。再一次,问题的标签是 excel
和 excel-formula
。如果需要,我可能会尝试用户定义的函数。