Как изменить имя таблицы, если имя и индекс таблицы неизвестны и используется значение переменной для имени?
Я создал пользовательский форум для вставки новой учетной записи в Excel.Я пытаюсь вставить новую учетную запись, скопировав таблицу влево и вставив ее в числовом порядке.
На этом листе 138 таблиц.
Я успешно дошел до этого момента, но не могу понять, как изменить имя новой таблицы.Все таблицы называются «Ledger_ (Номер счета)».
Может кто-нибудь помочь мне понять, как найти новую таблицу и изменить имя?Я могу найти новое имя таблицы, но не могу понять, как использовать ее для изменения ее имени.У меня было это так, что это изменило одно из имен таблиц раньше, но это была неправильная таблица, и с тех пор я точно забыл, что я сделал, чтобы заставить это сделать это.Пожалуйста, помогите мне.
Sub AddtoLedger()
' This is a test macro to find the correct place for the new account on
the Ledger
Dim LedgerAccountCell As Long
Dim tbxAccountName As String
Dim cbxAccountType As String
Dim tbxAccountNumber As Long
Dim AccountName As String
Dim AccountType As String
Dim AccountNumber As Long
Dim NewAccountNumberCellLedger As String
Dim OldTable As ListObject
Dim OldTableName As String
AccountName = CreateNewAccountForm.tbxAccountName.Value
AccountType = CreateNewAccountForm.cbxAccountType.Value
AccountNumber = 1002
'''CreateNewAccountForm.tbxAccountNumber.Value
'More Code Between here that loops through to find the correct numerical order 'to add the new account
Debug.Print ThisWorkbook.Worksheets("Ledger").Cells(8, LedgerAccountCell + 9).ListObject.Name
' This gives me the correct name of the new table "Ledger_1001155"
' I am trying to change the name from Ledger_1001155 to Ledger 1002
'This will change the name of the new table that was coppied to have the appropriate name
Set OldTable = ThisWorkbook.Worksheets("Ledger").Cells(8, LedgerAccountCell + 9).ListObject.DisplayName
ThisWorkbook.Worksheets("Ledger").Cells(8, LedgerAccountCell `+ 9).ListObject.Add.Name = "Ledger_" & AccountNumber
ThisWorkbook.Worksheets("Ledger").ListObject.Name = "Ledger_" enter code here& AccountNumber