enter image description hereMy code was running running smoothly until I added columns to a named range table. I had to reset all of the table names, thereafter, the variable referring to the tables could not be found. When I create a new table and reference the new table, the code runs. Im trying to avoid creating new tables every time. Please assist me not to break the reference when changing table names.
错误是
运行时错误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: