变更表格名称

时间:2019-09-25 19:17:03

标签: excel vba

当表名和索引未知并且使用变量值作为名称时,如何更改表名?

我创建了一个用户论坛,用于将新帐户插入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

0 个答案:

没有答案