Guest User

Untitled

a guest
Mar 17th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. =GETPIVOTDATA("Sum of MyField",B9,"This",Table1[@This])
  2.  
  3. Option Explicit
  4.  
  5. Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
  6.  
  7. If Target.Name = "PivotTable1" Then
  8.  
  9. Dim wb As Workbook
  10. Dim ws As Worksheet
  11. Dim pvt As PivotTable
  12. Dim numberOfPivotRows
  13. Dim targetColumn As Range
  14.  
  15. Set wb = ThisWorkbook
  16. Set ws = wb.Worksheets("Sheet1")
  17. Set pvt = Target
  18. numberOfPivotRows = pvt.DataBodyRange.Rows.Count
  19. Set targetColumn = ws.Range("Table2[Column1]") 'put the correct sheet name, table name and target column where you want to write your values to
  20.  
  21. If targetColumn.Rows.Count < numberOfPivotRows Then
  22.  
  23. With targetColumn
  24.  
  25. .Resize(numberOfPivotRows, 1).FillDown
  26.  
  27. End With
  28.  
  29. End If
  30.  
  31. End If
  32.  
  33. End Sub
Add Comment
Please, Sign In to add comment