1

Im trying to work on a data in a pivot table by selecting it first but except for the grand Totals. I still want the grand totals to be displayed. when I write:

ActiveSheet.PivotTables("PivotTable1").DataBodyRange.select

I get this: enter image description here

(all the data including the grand totals is selected)

but I want it to be like this: enter image description here

How can I ignore the grand totals when selecting the data?

4

1 回答 1

1

Resize可以更改所选范围的大小:

Dim rng As Range
Set rng = ActiveSheet.PivotTables(1).DataBodyRange
rng.Resize(rng.Rows.Count - 1, rng.Columns.Count - 1).Select

rng.Rows.Count - 1负责将行数减少 1。我不得不将列压缩 1 以将两个总计排除在选择之外。

如果您不喜欢,您可以一次性完成Dim

ActiveSheet.PivotTables(1).DataBodyRange.Resize(ActiveSheet.PivotTables(1).DataBodyRange.Rows.Count - 1, ActiveSheet.PivotTables(1).DataBodyRange.Columns.Count-1).Select
于 2015-11-05T11:09:42.867 回答