0

ピボット テーブルの選択領域を選択してコピーしようとしています。必要な領域の量を決定でき、目的ではないメッセージ ボックスに範囲を表示できます。その選択範囲をコピーしたい。私のコードは次のようになります。範囲内の値をコピーしたい (toprow1,leftcoloumn:lastrow,rightcoloumn)。参考までに、メッセージ ボックスのコードは必要ありません。

    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
4

1 に答える 1

1

コピーしたいのは値だけだと思いますか?もしそうなら、このようなものから始めてみてください - 範囲 A1 から始まる Sheet2 に値を入れます。ピボット テーブルのどの範囲をどこにコピーするのかわかりません。これをいくつか変更する必要があります。

Sub CopyRange()

Dim vArray() As Variant

'Copies the values between (Toprow1, LeftColumn) and (LastRow, RightColumn) into an array
vArray = ActiveSheet.Range(Cells(TopRow1, LeftColumn), Cells(LastRow, RightColumn)).Value
'Pastes the values from the array into Sheet2, starting at A1
Sheet2.Range("A1").Resize(UBound(vArray, 1), UBound(vArray, 2)).Value = vArray

End Sub
于 2013-02-13T12:54:43.753 に答える