[英]How would I use VBA to automatically populate an excel worksheet with data from the pivot table of a separate excel workbook?
[英]How do I select data from the excel pivot table?
Sub SelectAndCopyPaste()
Dim lastrow() As String
Dim pt As PivotTable
Worksheets("Sheet1").Activate
ActiveSheet.Cells.Clear
With Worksheets("Pivot Sheet")
.Activate
Set pt = .PivotTables("PivotTable2")
lastrow = Split(pt.RowRange.Address, ":")
.Range(lastrow(1)).Offset(-1, 6).Select 'here is where you set which cell you want to choose
Selection.ShowDetail = True
Selection.Copy
End With
Worksheets("Sheet1").Select
ActiveSheet.Cells(1, 1).PasteSpecial xlPasteValues
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.