いいえ、それはこのピボット専用の新しいシートではありません @SiddharthRout – 初心者 4 分前
最も簡単な方法は、
With ActiveWorkbook
.Sheets("Tabelle2").Cells.Clear
.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"sourcetable!R1C1:R1048576C21", Version:=xlPivotTableVersion14). _
CreatePivotTable TableDestination:="Tabelle2!R3C1", TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion14
End With
また、行 1048576 までソース データが定義されていることに気付きました。なぜですか? より完璧な方法は、最後の行を見つけてから範囲を構築することです。例えば
Sub Sample()
Dim lRow As Long
With ActiveWorkbook
'~~> Find last row in sheet sourcetable
With .Sheets("sourcetable")
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
lRow = .Cells.Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Else
lRow = 1
End If
End With
.Sheets("Tabelle2").Cells.Clear
.PivotCaches.Create(SourceType:=xlDatabase, _
SourceData:="sourcetable!R1C1:R" & _
lRow & _
"C21", _
Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:="Tabelle2!R3C1", _
TableName:="PivotTable1", _
DefaultVersion:=xlPivotTableVersion14
End With
End Sub