列出对象表命名范围

时间:2020-05-08 21:05:19

标签: excel vba listobject excel-tables

enter image description here

我的代码运行平稳,直到我将列添加到命名范围表中为止。我必须重置所有表名,此后,找不到指向表的变量。创建新表并引用新表时,代码将运行。我试图避免每次都创建新表。请协助我更改表名时不要破坏引用。

错误是

运行时错误91:未设置对象变量或块变量。

If ServicesLine2 = "" Then
GoTo Ne2 'Exit the loop if a mtch is not foun d
    Dim PrRange2 As Range
    Dim cell2 As Range
    Dim ItemR2 As Double, UnitPrice2, HrRate2
    Dim ItemRange2 As Range
    Dim PrTable2 As ListObject ''the Table Im looking for information from
    ''declare a column range  (Item number) in th table. all variables checked (PricingTableServiceLine2_10) -table name
    Set ItemRange2 = shPrice2.Range("PricingTableServiceLine2_10[Item Number]")
    ''declare a column range  (Item) in th table. (PricingTableServiceLine2_10) -table name
    Set PrRange2 = shPrice2.Range("PricingTableServiceLine2_10[Item]")

    For Each cell2 In PrRange2
        If ServicesLine2 = cell2.Value Then
'                ''Get variables in the matching row
                ItemR2 = cell2.row - shPrice2.Range("PricingTableServiceLine2_10[[#Headers],[Item]]").row
                Itemnumber = shPrice2.Range("PricingTableServiceLine2_10[Item Number]").Cells(ItemR2, 1).Value
                HrRate2 = shPrice2.Range("PricingTableServiceLine2_10[HR Rate]").Cells(ItemR2, 1).Value
                UnitPrice2 = shPrice2.Range("PricingTableServiceLine2_10[Unit Price]").Cells(ItemR2, 1).Value
        End If
    Next cell2

End If
''I get the first two values but not the last
InvTable.ListColumns("Services Line 2").DataBodyRange(InvoiceR) = GooTable.ListColumns("Services Line 2").DataBodyRange(GoogleR).Value & _
" Prints"
InvTable.ListColumns("Item Number Line 2").DataBodyRange(InvoiceR) = Itemnumber

InvTable.ListColumns("Amount Line 2").DataBodyRange(InvoiceR) = PrTable2.ListColumns("Unit Price").DataBodyRange(ItemR2).Value


Ne2:

0 个答案:

没有答案
相关问题