• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Pivot table vba

sms2luv

Member
Hi
I have created a pivot table and copied it after a blank column for different parameter.
So in total there are 4 pivot table in a sheet.(same pivot with different metric).
All separated with blank column.
I created a copy button so that VBA can copy all pivot tables and paste it in outlook, I used range("a3,range("a4")). End(xldown).end(xlright), but its not selecting the pivots till the end.
All pivots are not of same size.
Please help.
 
This snippet selects a single rectangular range which encompasses all pivot tables on the active sheet. If there are more pivots on the sheet than you want to include then come back.
Code:
Sub blah()
Dim pvtrange As Range
MinColm = Columns.Count
maxColm = 0
minRow = Rows.Count
maxRow = 0
For Each pvt In ActiveSheet.PivotTables
  With pvt.TableRange2
  MinColm = Application.Min(MinColm, .Column)
  maxColm = Application.Max(maxColm, .Columns.Count + .Column - 1)
  minRow = Application.Min(minRow, .Row)
  maxRow = Application.Max(maxRow, .Rows.Count + .Row - 1)
  End With
Next pvt
Range(Cells(minRow, MinColm), Cells(maxRow, maxColm)).Select
End Sub
 
Back
Top