Hi There,
I've looked at many posts on this subject and unfortunately I cant seem to use them to stitch together a solution, so hope this new thread doesn't annoy people.
I have a workbook with just one worksheet in it, called 'Template_data'. The number of rows in this could change, so I want to select the range dynamically and then add a Pivot Table to a new worksheet called 'Summary by Provider'. The pivot table VBA I can get from recording the marco, but its selecting the region and then telling it to use that region for the pivot table and to then insert the pivot table onto a new sheet called 'Summary by Provider'. I've tried many different methods and now feel lost, can anyone help please?
I've looked at many posts on this subject and unfortunately I cant seem to use them to stitch together a solution, so hope this new thread doesn't annoy people.
I have a workbook with just one worksheet in it, called 'Template_data'. The number of rows in this could change, so I want to select the range dynamically and then add a Pivot Table to a new worksheet called 'Summary by Provider'. The pivot table VBA I can get from recording the marco, but its selecting the region and then telling it to use that region for the pivot table and to then insert the pivot table onto a new sheet called 'Summary by Provider'. I've tried many different methods and now feel lost, can anyone help please?
Code:
Sub DynamicRange1()'Best used when your data does not have any entirely blank rows or columns
Dim sht As Worksheet
Dim StartCell As Range
Set sht = Worksheets("Template_data")
Set StartCell = Range("A1")
'Select Range
StartCell.CurrentRegion.Select
With ActiveSheet.PivotTables("PivotTable12").PivotFields("ServiceProvider")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable12").AddDataField ActiveSheet.PivotTables( _
"PivotTable12").PivotFields("PlanValue_WrapSipp"), _
"Count of PlanValue_WrapSipp", xlCount
With ActiveSheet.PivotTables("PivotTable12").PivotFields( _
"Plan Valuation Type Group")
.Orientation = xlPageField
.Position = 1
End With
End Sub