gpt4 book ai didi

excel - 枢轴名称未分配,如何调试?

转载 作者:行者123 更新时间:2023-12-04 20:46:09 26 4
gpt4 key购买 nike

我创建了一个宏来为名为 的工作表中存在的数据创建数据透视表。 “数据” .我将枢轴的名称输入为 “数据透视”但是当创建数据透视表时,数据透视表的名称为 sheet1,我期待 “数据透视” ?

也可以帮助调试数据透视缓存吗?我的意思是除了宏中的任何监视之外,数据如何缓存在数据透视缓存中以查看数据透视缓存中的内容和内容?

任何帮助,将不胜感激。

我的代码:

'To set up my workbook & worksheet variables.
Dim bReport As Workbook, Report As Worksheet, pivotSheet As Worksheet
Set bReport = Excel.ActiveWorkbook
Set Report = bReport.Worksheets("data") 'Create the worksheet to place the SQL data
Set pivotSheet = bReport.Worksheets.Add 'Create the worksheet to place the Pivot Table

Dim pivotSource As Range 'To set up the variable representing your pivot data.
Set pivotSource = Report.UsedRange 'selecting entire data in the sheet

Dim tableName As String
tableName = "Pivot_Data" 'name of pivot report i wanted to create from data in sheet Prod

bReport.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=pivotSource).CreatePivotTable _
TableDestination:=pivotSheet.Cells(1, 1), tableName:=tableName

Set pt = pivotSheet.PivotTables(tableName)
pivotSheet.PivotTableWizard TableDestination:=pivotSheet.Cells(1, 1)
Set pOne= pt.PivotFields("Number")
Set pTwo = pt.PivotFields("Premium")
Set pthree = pt.PivotFields("TransactoinID")
Set pFour = pt.PivotFields("money")

pOne.Orientation = xlRowField 'This assigns the orientation of a given field to xlRowField.
pTwo.Orientation = xlRowField
pTwo.Subtotals(1) = False 'This denotes there will be no subtotal for this field.
pThree.Orientation = xlRowField
pThree.Subtotals(1) = False
pFour.Orientation = xlDataField
pFour.NumberFormat = "$#,##0.00"

最佳答案

要命名工作表,您需要添加另一行代码来重命名它:

Set pivotSource = Report.UsedRange 

Dim tableName As String
tableName = "Pivot_Data"
pivotSheet.Name = tableName '<~~ new line to change sheet name

关于excel - 枢轴名称未分配,如何调试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16250370/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com