错误' 1004'方法'范围'对象' _Global失败

时间:2014-04-27 10:46:15

标签: excel vba excel-vba

我想从一张工作表中的一个数据透视表中根据产品ID行字段获取销售数据的总和,以将其放入另一个工作表中。我打算逐行执行循环,因为我想修改并在 Sales 的修改总和上执行匹配功能。

但我一直遇到:error 1004 Method 'Range' of object'_Global failed

在线错误(突出显示):ws3.Range(ws2.Cells(i, 36)) = PvtTbLA.GetPivotData("Sales", "Product ID", Range(ws2.Cells(i, 3)))

代码:

Sub Testing()

    Dim ws As Worksheet
    Dim ws2 As Worksheet
    Dim myCountRows As Integer
    Dim PvtTbLA As PivotTable
    Dim PvtTbNY As PivotTable
    Set ws = Worksheets("NY_Sales_PivotTable")
    Set ws2 = Worksheets("LA_Sales_PivotTable")
    Set PvtTbLA = Worksheets("LA Pivot Table").PivotTables("LA_PivotTable")
    Set PvtTbNY = Worksheets("NY_Monthly_Sales_TX_Pivot_Table").PivotTables("NY_PivotTable")

    ws.Range("AI5").Select
    myCountRows = Range(Selection, Selection.End(xlDown)).Count

    Dim i As Integer
    i = 5

    Do While i < myCountRows

        ws3.Range(ws2.Cells(i, 36)) = PvtTbLA.GetPivotData("Sales", "Product ID", Range(ws2.Cells(i, 3)))

        i = i + 1
    Loop

    '...

0 个答案:

没有答案