处理Excel公式长度

时间:2013-03-12 14:44:41

标签: excel excel-vba excel-formula vba

在成功进行数据库/应用程序开发之后,我的任务是创建一个非常先进的电子表格供我们的招聘团队使用。

长话短说,有一个公式可以计算出营地中“必需的员工”和“与会者”。

通过ODBC连接将出勤和人员数据拉到另外两个工作表,并转换为漂亮的数据透视表。

有一个相当容易理解,但最终编程复杂的计算要完成。这大约需要8个步骤。

鉴于[据我所知]你不能在一个单元格中制作短期变量,并且结合引用外部单元格的事实需要相当多的字符,我最终得到了一个视觉上(如果没有)概念上)复杂的公式。

最终......因为我已经使用IFERROR()添加了一些数据验证来解决数据的不确定性,这意味着我实际上达到了一个单元格的字符数限制(大约8100个字符)。我试过FSVO缩小细胞,这并没有让我回到限制之下。

所以 - 现在你知道了问题 - 这是一组问题:

  • 有没有办法延长限额?
  • 有没有办法在单元格内部创建变量(这也可以解决问题)?
  • VB适合这类问题吗?

我怀疑答案是:“去学习一些VB”......这是我试图避免的。我估计我差不多有3行,鉴于它是一个久经考验的解决方案,重新编码就很遗憾。

编辑包含公式

=IF(
    OR(
        IFERROR(
        GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","4/5 years","Activity","Multi-Active","date",B$1-DATE(YEAR(B$1),1,0)),0),
        IFERROR(
        GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","6/7 years","Activity","Multi-Active","date",B$1-DATE(YEAR(B$1),1,0)),0),
        IFERROR(
        GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","8 + years","Activity","Multi-Active","date",B$1-DATE(YEAR(B$1),1,0)),0),

        IFERROR(
        GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","4/5 years","Activity","ISS","date",B$1-DATE(YEAR(B$1),1,0)),0),
        IFERROR(
        GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","6/7 years","Activity","ISS","date",B$1-DATE(YEAR(B$1),1,0)),0),
        IFERROR(
        GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","8 + years","Activity","ISS","date",B$1-DATE(YEAR(B$1),1,0)),0),

        IFERROR(
        GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","4/5 years","Activity","MVC","date",B$1-DATE(YEAR(B$1),1,0)),0),
        IFERROR(
        GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","6/7 years","Activity","MVC","date",B$1-DATE(YEAR(B$1),1,0)),0),
        IFERROR(
        GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","8 + years","Activity","MVC","date",B$1-DATE(YEAR(B$1),1,0)),0)
    ),

 SUM(
        IF(
            OR(
                IFERROR(
                GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","4/5 years","Activity","Multi-Active","date",B$1-DATE(YEAR(B$1),1,0)),0),
                IFERROR(
                GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","6/7 years","Activity","Multi-Active","date",B$1-DATE(YEAR(B$1),1,0)),0),
                IFERROR(
                GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","8 + years","Activity","Multi-Active","date",B$1-DATE(YEAR(B$1),1,0)),0)
            ),
                SUM(
                    (
                    (IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","4/5 years","Activity","Multi-Active","date",B$1-DATE(YEAR(B$1),1,0)),0)+($B$49-MOD(IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","4/5 years","Activity","Multi-Active","date",B$1-DATE(YEAR(B$1),1,0)),0),$B$49)))/$B$49
                    )
                    +
                    (
                    ((IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","6/7 years","Activity","Multi-Active","date",B$1-DATE(YEAR(B$1),1,0)),0)-($B$49-MOD(IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","4/5 years","Activity","Multi-Active","date",B$1-DATE(YEAR(B$1),1,0)),0),$B$49)))+($B$50-(MOD((IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","6/7 years","Activity","Multi-Active","date",B$1-DATE(YEAR(B$1),1,0)),0)-($B$49-MOD(IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","4/5 years","Activity","Multi-Active","date",B$1-DATE(YEAR(B$1),1,0)),0),$B$49))),$B$50))))/$B$50
                    )
                    +
                    (
                    CEILING(
                        IF(
                            ((IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","8 + years","Activity","Multi-Active","date",B$1-DATE(YEAR(B$1),1,0)),0)-($B$50-(MOD((IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","6/7 years","Activity","Multi-Active","date",B$1-DATE(YEAR(B$1),1,0)),0)-($B$49-MOD(IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","4/5 years","Activity","Multi-Active","date",B$1-DATE(YEAR(B$1),1,0)),0),$B$49))),$B$50))))/$B$51)<0,
                            0,
                            (
                            (IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","8 + years","Activity","Multi-Active","date",B$1-DATE(YEAR(B$1),1,0)),0)-($B$50-(MOD((IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","6/7 years","Activity","Multi-Active","date",B$1-DATE(YEAR(B$1),1,0)),0)-($B$49-MOD(IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","4/5 years","Activity","Multi-Active","date",B$1-DATE(YEAR(B$1),1,0)),0),$B$49))),$B$50))))/$B$51
                            )
                        ),1
                    )
                    )
                )
                ,
                0
        )
        +

        IF(
            OR(
                IFERROR(
                GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","4/5 years","Activity","ISS","date",B$1-DATE(YEAR(B$1),1,0)),0),
                IFERROR(
                GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","6/7 years","Activity","ISS","date",B$1-DATE(YEAR(B$1),1,0)),0),
                IFERROR(
                GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","8 + years","Activity","ISS","date",B$1-DATE(YEAR(B$1),1,0)),0)
            ),      
            SUM(
                (
                (IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","4/5 years","Activity","ISS","date",B$1-DATE(YEAR(B$1),1,0)),0)+($B$49-MOD(IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","4/5 years","Activity","ISS","date",B$1-DATE(YEAR(B$1),1,0)),0),$B$49)))/$B$49
                )
                +
                (
                ((IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","6/7 years","Activity","ISS","date",B$1-DATE(YEAR(B$1),1,0)),0)-($B$49-MOD(IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","4/5 years","Activity","ISS","date",B$1-DATE(YEAR(B$1),1,0)),0),$B$49)))+($B$50-(MOD((IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","6/7 years","Activity","ISS","date",B$1-DATE(YEAR(B$1),1,0)),0)-($B$49-MOD(IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","4/5 years","Activity","ISS","date",B$1-DATE(YEAR(B$1),1,0)),0),$B$49))),$B$50))))/$B$50
                )
                +
                (
                    CEILING(
                    IF(
                    ((IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","8 + years","Activity","ISS","date",B$1-DATE(YEAR(B$1),1,0)),0)-($B$50-(MOD((IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","6/7 years","Activity","ISS","date",B$1-DATE(YEAR(B$1),1,0)),0)-($B$49-MOD(IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","4/5 years","Activity","ISS","date",B$1-DATE(YEAR(B$1),1,0)),0),$B$49))),$B$50))))/$B$51)<0,
                    0,
                    (
                    (IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","8 + years","Activity","ISS","date",B$1-DATE(YEAR(B$1),1,0)),0)-($B$50-(MOD((IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","6/7 years","Activity","ISS","date",B$1-DATE(YEAR(B$1),1,0)),0)-($B$49-MOD(IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","4/5 years","Activity","ISS","date",B$1-DATE(YEAR(B$1),1,0)),0),$B$49))),$B$50))))/$B$51
                    )
                    ),1
                    )
                )
            )
            ,
            0
        )       
        +
        SUM(
                (
                (IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","4/5 years","Activity","MVC","date",B$1-DATE(YEAR(B$1),1,0)),0)+($B$49-MOD(IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","4/5 years","Activity","MVC","date",B$1-DATE(YEAR(B$1),1,0)),0),$B$49)))/$B$49
                )
                +
                (
                ((IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","6/7 years","Activity","MVC","date",B$1-DATE(YEAR(B$1),1,0)),0)-($B$49-MOD(IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","4/5 years","Activity","MVC","date",B$1-DATE(YEAR(B$1),1,0)),0),$B$49)))+($B$50-(MOD((IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","6/7 years","Activity","MVC","date",B$1-DATE(YEAR(B$1),1,0)),0)-($B$49-MOD(IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","4/5 years","Activity","MVC","date",B$1-DATE(YEAR(B$1),1,0)),0),$B$49))),$B$50))))/$B$50
                )
                +
                (
                CEILING(
                        IF(
                         ((IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","8 + years","Activity","MVC","date",B$1-DATE(YEAR(B$1),1,0)),0)-($B$50-(MOD((IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","6/7 years","Activity","MVC","date",B$1-DATE(YEAR(B$1),1,0)),0)-($B$49-MOD(IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","4/5 years","Activity","MVC","date",B$1-DATE(YEAR(B$1),1,0)),0),$B$49))),$B$50))))/$B$51)<0,
                         0,
                         (
                         (IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","8 + years","Activity","MVC","date",B$1-DATE(YEAR(B$1),1,0)),0)-($B$50-(MOD((IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","6/7 years","Activity","MVC","date",B$1-DATE(YEAR(B$1),1,0)),0)-($B$49-MOD(IFERROR(GETPIVOTDATA("Child ID",'Child Numbers 2013'!$A$1,"Venue",$A4,"Age group","4/5 years","Activity","MVC","date",B$1-DATE(YEAR(B$1),1,0)),0),$B$49))),$B$50))))/$B$51
                         )
                        ),1
                    )
                )
        )       
 ),

 "-"
)

1 个答案:

答案 0 :(得分:0)

已定义的名称破解了它。仅供参考 - 我已经将对外部数据透视表的引用重新定义为CN而不是全名,并且已经保存了数百个字符。 谢谢大家!我已经标记了所有建议的人。