Hi Team,
I am unable to create New pivot table in summary sheet. below is my attempted code.
Below are the variable which stores inofrmation.
?NewRange
'Debtors Report'!R4C1:R41451C58.... Source
?rng_destination -- Pivot trying to store here.
'Summary'!R3C1
?wb.name
Debtors Report Apr 19 to Jan 21_22.01.2021.xlsb
Set pt = pc.CreatePivotTable(rng_destination, "Debtor Summary Report")................ pt shows nothing here
pt.AddFields (Array("Responsibility", "Remarks")), "Ageing Bucket"
Thanks
mg
End With
I am unable to create New pivot table in summary sheet. below is my attempted code.
Below are the variable which stores inofrmation.
?NewRange
'Debtors Report'!R4C1:R41451C58.... Source
?rng_destination -- Pivot trying to store here.
'Summary'!R3C1
?wb.name
Debtors Report Apr 19 to Jan 21_22.01.2021.xlsb
Set pt = pc.CreatePivotTable(rng_destination, "Debtor Summary Report")................ pt shows nothing here
pt.AddFields (Array("Responsibility", "Remarks")), "Ageing Bucket"
VBA Code:
Sub Refresh_Pivot(ByVal sht_Source As Worksheet, ByVal wb As Workbook, ByVal sht_Pivot As Worksheet)
Dim LastCol As Long
Dim rng_source As Range
Dim LastRow As Long
Dim NewRange As String
Dim pt As PivotTable
Dim pf As PivotField
Dim key1 As Range
Dim pc As PivotCache
Dim rng_destination As String
With sht_Source
LastCol = sht_Source.Cells(4, .Columns.Count).End(xlToLeft).Column
LastRow = sht_Source.Cells(.Rows.Count, 1).End(xlUp).Row
Set rng_source = .Range(.Cells(4, 1), .Cells(LastRow, LastCol))
End With
NewRange = "'" & sht_Source.Name & "'!" & _
rng_source.Address(ReferenceStyle:=xlR1C1)
rng_destination = "'" & sht_Pivot.Name & "'!" & sht_Pivot.Range("A3").Address(, , xlR1C1)
Set pt = sht_Pivot.PivotTables(1)
Set pc = wb.PivotCaches.Create( _
SourceType:=xlDatabase, _
SourceData:=NewRange)
'---------Delete Pivot-----------
For Each pt In sht_Pivot.PivotTables
pt.TableRange2.Clear
Next pt
Set pt = pc.CreatePivotTable(rng_destination, "Debtor Summary Report")
pt.AddFields (Array("Responsibility", "Remarks")), "Ageing Bucket"
With pt.PivotFields("Outstanding Balance")
.Orientation = xlDataField
.Function = xlSum
.Caption = "Sum of Outstanding Balance"
end sub
Thanks
mg
End With