Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 更改作为表副本的表的名称_Excel_Vba - Fatal编程技术网

Excel 更改作为表副本的表的名称

Excel 更改作为表副本的表的名称,excel,vba,Excel,Vba,一张纸上有138张桌子 我创建了一个userform来插入一个新帐户。我试图通过将表复制到左侧并按数字顺序粘贴来插入新帐户 如何更改新表的名称。所有表格均命名为“分类账(账号)” 我可以找到新表,但我不知道如何更改它的名称 Sub AddtoLedger() ' This is a test macro to find the correct place for the new account on the Ledger Dim LedgerAccountCell As Long Dim

一张纸上有138张桌子

我创建了一个userform来插入一个新帐户。我试图通过将表复制到左侧并按数字顺序粘贴来插入新帐户

如何更改新表的名称。所有表格均命名为“分类账(账号)”

我可以找到新表,但我不知道如何更改它的名称

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

sheet.ListObjects(oldName).Name=newName
?如何让它识别(oldName)?我尝试将其设置为变量,但无法使其工作。有什么想法吗?让我也澄清一下。因为新表每次都会更改名称,我不知道如何让它检索新表“oldname”并将其更改为“newname”。我不理解您的问题。你有一个
OldTable
对象,
oldName
OldTable.Name
。你太棒了。我不知道在旧桌子后面加“.name”。我正在努力学习和理解via的工作原理。你刚刚解决了几个小时的挫折。我对你感激不尽。谢谢马修·金登,干杯!我管理这个开源项目,它分析VBA代码,可以教你一些技巧,并警告你一些初学者的陷阱——看看吧!