繁体   English   中英

FormulaR1C1和“ = SUMIFS(”

[英]FormulaR1C1 and “=SUMIFS(”

我试图根据BUcode和业务Division ,将特定位置类型中处于占用位置的所有单位BUcode

注意:
-变量binshelv占用变量是工作表中定义的名称。
-变量除法BUcode在父代码中定义,该父代码调用并将这些值传递给此过程。

以下是我尝试输入的代码:

ActiveCell.FormulaR1C1 = _
    "=IF(" & _
        "" & BUcode & "=Overall," & _
        "if(" & _
                "" & Division & "=Overall, " & _
                "SUMIFS(" & _
                        "DataDump[On Hand Qty (Units)]," & _
                        "DataDump[Occupied?], occupied," & _
                        "DataDump[Location Short Description], binshelv" & _
                ")," & _
                "Sumifs(" & _
                        "DataDump[On Hand Qty (Units)]," & _
                        "DataDump[Occupied?], occupied," & _
                        "DataDump[Location Short Description], binshelv," & _
                        "DataDump[Division Code], " & DivCode & "," & _
                ")" & _
        ")," & _
        "SUMIFS(" & _
                "DataDump[On Hand Qty (Units)]," & _
                "DataDump[Business Unit]," & BUcode & "," & _
                "DataDump[Location Short Description], binshelv" & _
        ")" & _

    ")"

为什么我当前会收到Error '1004'

看来问题在于您的公式不等于有效的字符串。 如果将以下代码复制并粘贴到VBA编辑器中,则会看到strFormula不等于有效字符串。 这意味着您在公式中有一个错误。 要记住的一件事是,您需要在公式中使用双引号引起来,或者使用转义字符来在字符串中使用文字引号。

尝试使“ strFormula =“等于有效字符串。

Sub aa()

    Dim strFormula As String
    Dim binshelv, occupied, Division, BUcode As String

    ' **--- Get this line to equate to a valid string**
    strFormula = _
    "=IF(" & _
    "" & BUcode & "=Overall," & _
    "if(" & _
            "" & Division & "=Overall, " & _
            "SUMIFS(" & _
                    "DataDump[On Hand Qty (Units)]," & _
                    "DataDump[Occupied?], occupied," & _
                    "DataDump[Location Short Description], binshelv" & _
            ")," & _
            "Sumifs(" & _
                    "DataDump[On Hand Qty (Units)]," & _
                    "DataDump[Occupied?], occupied," & _
                    "DataDump[Location Short Description], binshelv," & _
                    "DataDump[Division Code], " & DivCode & "," & _
            ")" & _
    ")," & _
    "SUMIFS(" & _
            "DataDump[On Hand Qty (Units)]," & _
            "DataDump[Business Unit]," & BUcode & "," & _
            "DataDump[Location Short Description], binshelv" & _
    ")" & _
    ")"

    ActiveCell.FormulaR1C1 = strFormula
End Sub

使用双引号来表示文字引号

=SUMIFS(C8:C11,A8:A11,"colACriteria",B8:B11,"ColBCriteria")

进入

"=SUMIFS(C8:C11,A8:A11,""colACriteria"",B8:B11,""ColBCriteria"")"

暂无
暂无

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

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