Excel VBA - 包含变量抛出“未定义”错误的公式

时间:2016-05-12 13:45:33

标签: excel vba excel-vba

我正在尝试创建一个宏,在这里我输入动态范围的小计,给定一个过滤列表,动态范围存储为变量(lastRow2014)。但是,我在尝试创建公式的行中收到应用程序或对象定义的错误。我尝试在线搜索以确保语法正确,似乎是。我已经包含了相关的代码(虽然还有更早的代码,但我不希望它太长。

    'For ATRT, we'll need to vlookup the 2016 data since it's not currently formatted.
    Range("AB11").Formula = "=VLOOKUP(Y11,P:U,6,FALSE)"
    Range("AB11").AutoFill Destination:=Range("AB11:AB" & lastRow2014)


    'Now, let's calculate the percentage.  The trick will be the reference.
    Range("AA4").Formula = "='Summary 2'!M3" 'This is the index from the summary tab
    Range("AC10").Value = "Within?"
    Range("AC11").Formula = "=IF(AND(Z11 <=(AA11 + ($AA$4 * AA11)), Z11 >= (AA11 - (AA11 * $AA$4))), ""WITHIN"", ""NOT"")"
    Range("AC11").AutoFill Destination:=Range("AC11:AC" & lastRow2014)
    'Let's test this first before we continue.  This will all help us get the Filters for "Within"?  Dynamically based on the filter entry.
    'From here we'll get the ATRT, counts, etc.


    'For TOTAL data, we will make sure the filters are set.  Wait... I think this only applies to SHARED.

    Range("A10").AutoFilter Field:=11, Criteria1:="1"
     Range("A10").AutoFilter Field:=29, Criteria1:= _
        "WITHIN"

    'ATRT 2014
   Range("U5").Formula = "=SUBTOTAL(9,Z11:Z & ""lastRow2014"")"
   Range("V5").Formula = "=SUBTOTAL(9,J11:J & ""lastRow2014"")"
   Range("U6").Formula = "=V5/U5"

0 个答案:

没有答案