枢纽名称没有得到分配,如何debugging?

我创build了一个macros来为名为“data”的工作表中的数据创build一个数据透视表。 我把枢轴的名称作为“Pivot_Data”,但是当枢轴被创build的名称来作为sheet1的数据透视表,我期待“Pivot_Data”

也可以帮助debugging数据透视caching以及? 我的意思是除了macros中的任何手表以外,如何将数据caching到数据透视caching中,以查看数据透视表中的人员和数据。

任何帮助,将不胜感激。

我的代码:

'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