Hi,
I have to copy and paste the last column of the pivot table to the next empty column. Here is the code for that I have used. The problem is I have multiple pivot table in the same sheet, and I would like to copy the last column of each pivot table into the next empty column. The no.of columns in each pivot table vary but the no.of rows are fixed. Kindly look into the attached file. vba.jpg
Sub test()
With ActiveSheet.PivotTables(1).TableRange1
Rows("4:27").Activate
last_colum = Cells.Find("*", [A1], searchorder:=xlByColumns, searchdirection:=xlPrevious).Column
vArray = ActiveSheet.Range(Cells(4, last_colum), Cells(27, last_colum)).Value
Cells(4, last_colum + 1).Resize(UBound(vArray, 1), UBound(vArray, 2)).Value = vArray
End With
With ActiveSheet.PivotTables(2).TableRange1
Rows("33:56").Activate
last_column = Cells.Find("*", [A1], searchorder:=xlByColumns, searchdirection:=xlPrevious).Column
vArray = ActiveSheet.Range(Cells(33, last_column), Cells(56, last_column)).Value
Cells(33, last_column + 1).Resize(UBound(vArray, 1), UBound(vArray, 2)).Value = vArray
End with
End Sub
The code works for the first pivot table but not for the second. Please help.
Thanks,
GK
Bookmarks