![enter image description here](https://i.stack.imgur.com/VyZ9m.jpg)
Мой код работал плавно, пока я не добавил столбцы в таблицу именованного диапазона. Мне пришлось сбросить все имена таблиц, после чего переменная, относящаяся к таблицам, не могла быть найдена. Когда я создаю новую таблицу и ссылаюсь на нее, код запускается. Я пытаюсь каждый раз не создавать новые таблицы. Пожалуйста, помогите мне не нарушить ссылку при изменении имен таблиц.
Ошибка:
Ошибка времени выполнения 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: