Tried Searching through the forum but cannot seem to find anything on it - sorry if I missed it ...
Anyway, I am trying to create a VBA macro for fairly simple Pivot Table on a running report. Each week I get new data, similar data that has new values. I am looking to dump the data into each/new tab each week, run the macro, and have it display a new pivot table - within the (new) active worksheet. So there will be 52 weeks, 52 tabs, each with a Pivot Table. My problem lies with having to name the table within the VBA.
Is there a way to not set up a Pivot Name and have it default to whatever it wants within the new worksheet?
Or possibly a way to have it dynamically name itself using the active, given worksheet?
What I got so far:
Thanks guys!
Anyway, I am trying to create a VBA macro for fairly simple Pivot Table on a running report. Each week I get new data, similar data that has new values. I am looking to dump the data into each/new tab each week, run the macro, and have it display a new pivot table - within the (new) active worksheet. So there will be 52 weeks, 52 tabs, each with a Pivot Table. My problem lies with having to name the table within the VBA.
Is there a way to not set up a Pivot Name and have it default to whatever it wants within the new worksheet?
Or possibly a way to have it dynamically name itself using the active, given worksheet?
What I got so far:
Code:
Option Explicit
Public strPageName As String
Public strRowName As String
Public strColumnName As String
Public strDataName As String
Sub Format()
Rows("1:5").Select
Selection.Delete Shift:=xlUp
Range("A1:J1").Select
Selection.UnMerge
Range("A1").Select
ActiveCell = "Vendor #"
Range("B1").Select
ActiveCell = "Vendor Name"
Range("D1").Select
ActiveCell = "Parent Company"
Range("F1").Select
ActiveCell = "Retailer"
Range("H1").Select
ActiveCell = "Part Description"
Range("I1").Select
ActiveCell = "Part #"
Range("M1").Select
ActiveCell = "Week 1 Net"
End Sub
Public Sub MakePivot()
Dim Destination As Range
Dim DataRange As Range
Set Destination = ActiveSheet.Range("V4")
Set DataRange = Range("A1", Range("T1").End(xlDown))
ActiveWorkbook.PivotCaches.Create _
(SourceType:=xlDatabase, SourceData:=DataRange) _
.CreatePivotTable TableDestination:=Destination
End Sub
Sub SetPivot()
Dim pvtTable As PivotTable
Set pvtTable = ActiveWorksheet.PivotTables
With pvtTable
.PivotFields(strPageName).Orientation = xlPageField
.PivotFields(strRowName).Orientation = xlRowField
.PivotFields(strColumnName).Orientation = xlColumnField
.PivotFields(strDataName).Orientation = xlDataField
End With
End Sub
Thanks guys!