pivottable groupdate and CalculatedItems

trantuan11

New Member
Joined
Mar 27, 2016
Messages
19
I have a code it doesn't work correctly, please help me
Sub addhideitems()
Dim WSD As Worksheet
Dim PTcache As PivotCache
Dim PT As PivotTable
Dim Prange As Range
Dim Finalrow As Long
Set WSD = Worksheets("sales")
Dim WSR As Worksheet
For Each PT In WSD.PivotTables
PT.TableRange2.Clear
Next PT
WSD.Range("u1:az1").EntireColumn.Delete
Finalrow = WSD.Cells(Rows.Count, 1).End(xlUp).Row
Finalcol = WSD.Cells(1, Columns.Count).End(xlToLeft).Column
Set Prange = Worksheets("sales").Cells(1, 1).Resize(Finalrow, Finalcol)
Set PTcache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=Prange.Address)
Set PT = PTcache.CreatePivotTable(TableDestination:=WSD.Cells(2, Finalcol + 2), TableName:="PivotTablesales")
PT.ManualUpdate = True
PT.AddFields RowFields:="rEGION", ColumnFields:="date"
PT.PivotFields("REGION").CalculatedItems.Add "MyDivision", "='BAO LAM'+'BAO LOC'"
' Resequence so that the report has A292 and C409 first
PT.PivotFields("REGION").PivotItems("BAO LAM").Position = 1
PT.PivotFields("REGION").PivotItems("BAO LOC").Position = 2
PT.PivotFields("REGION").PivotItems("MyDivision").Position = 3




With PT.PivotFields("credit")
.Orientation = xlDataField
.Function = xlSum
.Position = 1
.NumberFormat = "#,##0"
End With
PT.NullString = "0"
With PT.PivotFields("Region")


End With
With PT.PivotFields("REGION")
.PivotItems("BAO LAM").Visible = False
.PivotItems("BAO LOC").Visible = False
End With
PT.ManualUpdate = False
PT.ManualUpdate = True

' Group OrderDate by Month and Year
PT.PivotFields("date").LabelRange.Group Start:=True, End:=True, _
Periods:=Array(False, False, False, False, True, False, True)
PT.ManualUpdate = False
PT.ManualUpdate = True
WSD.Activate
Range("J2").Select



End Sub
tthank
 
Last edited:

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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