运行时错误'1004'对象'_Global'的方法'范围'失败 – dynamic表名,循环,工作表间search

我一直运行到Run-time error '1004' Method 'Range' of object '_Global' failed

在一个名为“Receiving”的工作表中,我有一个表(表是工作表中的唯一一个),它具有一个dynamic名称(表名称会随时更改),所以我将名称更改为“invoiceTable”子程序的开始。 基本上,我想遍历invoiceTable的行,并根据表中的数据修改其他工作表中的数据。

invoiceTable中的第一列叫做“Frame”,第五个叫做“Quantity Received”。 我试图通过invoiceTable循环,并根据invoiceTable中列出的框架更新名为“库存pipe理”的工作表中的数据。 对于invoiceTable中的每个框架,我想将'Quantity Received'添加到特定Frame的索引处的'Inventory Management'的列T中。

同样,我想从“单价”标题下的invoiceTable中取值,并使用invoiceTable中每个框架的最近购买价格更新“库存pipe理”列F中的值。

 ActiveSheet.ListObjects(1).Name = "invoiceTable" For row = 1 To Range("invoiceTable").Rows.Count If Range("invoiceTable[Frame]")(row).Value <> 0 Then Dim frame As String Dim purchQ As Integer Dim price As Long frame = Range("invoiceTable[Frame]")(row).Value price = Range("invoiceTable[Unit Price]")(row).Value purchQ = Range("invoiceTable[Quantity Received]")(row).Value Sheets("Inventory Management").Select Range("=OFFSET('Inventory Management'!F5,MATCH(frame,'Inventory Management'!B6:B41,0),0)").Value = price Range("=OFFSET('Inventory Management'!T5,MATCH(frame,'Inventory Management'!B6:B41,0),0)").Value = Range("=OFFSET('Inventory Management'!T5,MATCH(frame,'Inventory Management'!B6:B41,0),0)").Value + purchQ Sheets("Receiving").Select End If Next 

尝试使用此代码来代替处理“库存pipe理”表的4行:

 With Worksheets("Inventory Management") Dim FindFrame As Range Set FindFrame = .Range("B6:B41").Find(frame) If Not FindFrame Is Nothing Then .Cells(FindFrame.Row, 6) = Price .Cells(FindFrame.Row, 20) = .Cells(FindFrame.Row, 20) + purchq End If End With