[1]数据透视表选中(3种方法):
[a2].CurrentRegion.Select
[a2].PivotTable.TableRange2.Select 'First row, with the Report (Page) field
[a2].PivotTable.TableRange1.Select 'First row, without the Report (Page) field
PivotTables("").TableRange2.Cells(1,1).Address '$A$1
PivotTables("").TableRange2.Address '$A$1:$B$2
.TableRange2的前面写cells()或PivotTables("")都可以。
表头的行:cells().PivotTable.TableRange2.Row
底部的行:.Rows.Count + .Row - 1
左侧的列:.Column
右侧列:.Columns.Count + .Column - 1
[1]数据透视表的一些参数的获取
Sub PivotTableRangeAreas()
With ActiveSheet.PivotTables(1)
Dim TopRow1 As Long, TopRow2 As Long, LastRow As Long
Dim LeftColumn As Long, RightColumn As Long
TopRow2 = .TableRange2.Row
With .TableRange1
TopRow1 = .Row
LastRow = .Rows.Count + .Row - 1
LeftColumn = .Column
RightColumn = .Columns.Count + .Column - 1
End With
'MsgBox "The pivot table named " & .Name & vbCrLf & _
' "occupies these range elements:" & vbCrLf & vbCrLf & _
' "With the Report (Page) field: " & vbCrLf & _
' .TableRange2.Address(0, 0) & vbCrLf & _
' "Without the Report (Page) field: " & vbCrLf & _
' .TableRange1.Address(0, 0) & vbCrLf & vbCrLf & _
' "First row, with the Report (Page) field: " & TopRow2 & vbCrLf & _
' "First row, without the Report (Page) field: " & TopRow1 & vbCrLf & _
' "Last row: " & LastRow & vbCrLf & _
' "Left column: " & LeftColumn & vbCrLf & _
' "Right column: " & RightColumn, , "Pivot table location."
End With
End Sub
[1]当前单元格所在的数透表
Let PivName = Selection.PivotCell.Parent