VBA Code - Print a Heading between pivot tables created dynamically

snkatha

New Member
Joined
Feb 10, 2010
Messages
2
Hi,

I have been able to create pivot tables dynamically one after the another and I am also able to provide the gaps of 5 rows between the pivot tables. What I need is to insert a Heading for each of the pivot table.

For creating a pivot table, I use the following code. The "PivotTable1" already exists and the following code is to add a second pivot table "PivotTable2".

With ActiveSheet.PivotTables("PivotTable1")

Set rng = .TableRange1
.PivotCache.CreatePivotTable _
TableDestination:=rng.Offset(rng.Rows.Count + 5, 0).Cells(1, 1).Address(, , xlR1C1, True), _
TableName:="PivotTable2", _
DefaultVersion:=xlPivotTableVersion10

End With


Now, what I need is, I want to add a heading for each of the Pivot table that gets created. I am able to obtain the address of the range also.

MsgBox rng.Address

All I need is to identify the next row of the range and put my Heading. Is there any simple way to do this.

Thanks in advance.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Welcome to the Board.

This would put a heading 2 rows below PivotTable1:

rng.Offset(rng.Rows.Count + 2, 0).Cells(1, 1).Value = "Your Heading"
 
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,823
Members
449,470
Latest member
Subhash Chand

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top