Inserting a Pivot Table a few rows below a dynamic Range

Yeft

New Member
Joined
Jan 6, 2023
Messages
37
Office Version
  1. 365
Platform
  1. Windows
Hello , Any one who could help me with a macro for inserting my pivot Table a few rows below a Dynamic Range named "My Range"?
My data has 8 Columns and Headers are in Row 2. Pivot Table is to be placed in the same sheet , but under my dynamic Range.
Any help is much appreciated.
Thanks!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Probably you would insert your Pivot table in given cell of the sheet wit command similar to (for placement in J20 (so column 10 row 20):
VBA Code:
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "Sheet1!R2C10:R11C12", Version:=8).CreatePivotTable TableDestination:= _
        "Sheet1!R20C10", TableName:="PivotTable1", DefaultVersion:=8
But you want it in a specific place, let's say 5 rows below your dynamic range MyRange (spaces are not allowed in range names I think)
you shall calculate how many rows is there in MyRAnge, for instance like:
VBA Code:
dim rowsinnamed as long
rowsinnamed = UBound(Sheets("Sheet1").Evaluate("MyRange"))
let's say named range starts in row 15
then code shall be:

VBA Code:
dim rowsinnamed as long
rowsinnamed = UBound(Sheets("Sheet1").Evaluate("MyRange"))
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "Sheet1!R2C10:R11C12", Version:=8).CreatePivotTable TableDestination:= _
        "Sheet1!R" & 15 +rowsinnamed + 5 +1 & "C10", TableName:="PivotTable1", DefaultVersion:=8

so starting row + rowsinnamed + empty rows below + 1 for next row (not last of the above sum).Let us know if that works for you
 
Upvote 0
Solution
Hello kaper,

It did work perfectly!, Thank you so much!
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,120
Members
453,021
Latest member
Justyna P

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