Now i replace as j = ws1.Range("1:1").Find("ST").Column from is j = ws1.Range("1:1").Find("FT").Column its not take date into datafield
as well one more requirement i want select Q1-13 only in report filter add this condition in code.
Option Explicit
Sub pivt()
Dim r As Long 'rows
Dim c As Long 'columns
Dim j As Long 'number of months
Dim counter As Integer
Dim colField As String
Dim ws As Worksheet
Dim ws1 As Worksheet
Set ws1 = ActiveWorkbook.Sheets("Global Waterfall Schedule")
r = ws1.Range("A1").End(xlDown).Row
c = ws1.Range("A1").End(xlToRight).Column
On Error GoTo Err:
j = ws1.Range("1:1").Find("ST").Column - 1 'replace of j = ws1.Range("1:1").Find("CRM").Column - 1'
counter = 16 'replace of colunter = 10
Set ws = Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:="Global Waterfall Schedule!R1C1:R" & r & "C" & c).CreatePivotTable _
TableDestination:=ws.Name & "!R3C1", TableName:="PivotTable4"
With ActiveSheet.PivotTables("PivotTable4")
'no longer required
'.AddDataField ActiveSheet.PivotTables("PivotTable4").PivotFields("Capitalized Commissions"), "Sum of Capitalized Commissions", xlSum
'.PivotFields("CALL TYPE").Orientation = xlColumnField
'.PivotFields("Capitalized Commissions").NumberFormat = "#,##0.00_);[Red](#,##0.00)"
.TableStyle2 = ""
.RowAxisLayout xlCompactRow
.PivotFields("Capitalized Quarter").Orientation = xlPageField
.PivotFields("Capitalized Quarter").PivotItems("Q1-13").Visible = True
'i tried this
.PivotFields("Region").Orientation = xlRowField
.PivotFields("EVP-1").Orientation = xlRowField
.PivotFields("Cost Center").Orientation = xlRowField
.InGridDropZones = True
.RowAxisLayout xlTabularRow
For counter = 17 To j
colField = Format(ws1.Cells(1, counter), "dd-mmm-yy")
.AddDataField ActiveSheet.PivotTables("PivotTable4").PivotFields(colField), "Sum of " & colField, xlSum
Next counter
ActiveSheet.Name = "Amortization"
ActiveWindow.Zoom = 85
End With
MsgBox ("Pivot Done")
Exit Sub
Err:
MsgBox "ST header not found"
End Sub
Bookmarks