本文介绍了数据透视表宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞!我已经设置了一个小宏来从电子表格创建数据透视表:I have set up a small macro to create a pivot table from a spreadsheet: Sub CreatePivot() ''CreatePivot Macro '宏记录于3/14/2007由GarySub CreatePivot()'' CreatePivot Macro' Macro recorded 3/14/2007 by Gary ActiveWorkbook.PivotCaches.Add(SourceType:= xlDatabase,SourceData:= _ " Data!R1C1:R656C90" .CreatePivotTable TableDestination:="",TableName:= _ " PivotTable1",DefaultVersion:= xlPivotTableVersion10 ActiveSheet.PivotTableWizard TableDestination:= ActiveSheet.Cells( 3,1) ActiveSheet.Cells(3,1)。选择表格("Sheet1")。选择表格(" Sheet1")。Name =" Pivot" End Sub ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _ "Data!R1C1:R656C90").CreatePivotTable TableDestination:="", TableName:= _ "PivotTable1", DefaultVersion:=xlPivotTableVersion10 ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1) ActiveSheet.Cells(3, 1).Select Sheets("Sheet1").Select Sheets("Sheet1").Name = "Pivot" End Sub问题在于我运行的每个电子表格都有不同的行数。它们都具有相同的列数(A-CL),但行数不同。无论它有多少行,我都希望枢轴工作:即无论它是什么,它都会自动选择整个范围。这是可行的吗?The problem is that each spreadsheet I run it on, has a different number of rows. They all have the same number of columns (A-CL), but the number of rows varies. I'd like the pivot to work no matter how many rows it is: i.e., that it will automatically select the entire range whatever it is. Is this doable?谢谢, Gary推荐答案 Gary,Gary,你应该能够使用类似于以下代码获取工作表上使用的最后一行:You should be able to get the last row used on a sheet using code similar to: lastRow = ActiveSheet.Cells(Rows.Count,6).End(xlUp).Row'获取最后一行数据(在第6列中)lastRow = ActiveSheet.Cells(Rows.Count, 6).End(xlUp).Row 'get last row of data (in column 6)然后你可以使用"=数据!then you can use "=Data! A 1: 这篇关于数据透视表宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-24 18:03