Macro to dynamically place a Pivot table

KMaalouf

New Member
Joined
May 11, 2017
Messages
1
I have used this site a bunch over the years to figure out VB code, finally I think I have hit a wall that I cannot figure out from past posts.

I am trying to dynamically place a Pivot table. I have the code figured out to generate the pivot table but the macro will be used on varying amounts of rows and needs to have the pivot placed after the last row in column K. Right now I have it just defaulting in K47 and wish to have this value dynamically find the first blank row in "K" and skip one row and place the pivot table there.
Code:
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "Pivot!$A$1:OFFSET(Pivot!$A$1,COUNTA(Pivot!$A:$A)+1,1)", Version:=6).CreatePivotTable TableDestination:= _
        "Sheet1!R47C11", TableName:="PivotTable1", DefaultVersion:=6
    Sheets("Sheet1").Select
    Cells(47, 11).Select
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Fixture")
        .Orientation = xlRowField
        .Position = 1
    End With
    ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
        "PivotTable1").PivotFields("#"), "Count of #", xlCount
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of #")
        .Caption = "Sum of #"
        .Function = xlSum
    End With
    ActiveWorkbook.ShowPivotTableFieldList = False


Any help is appreciated
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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