PresidentEvil
New Member
- Joined
- Jan 2, 2021
- Messages
- 34
- Office Version
- 2021
- 2016
- Platform
- Windows
Hi All,
I'm trying to write a macro where in the final output is a pivot table with counts of transaction, name of processor, along with Follow up date.
Since the data I'm dealing with is in large number, I need only the data till 'current follow up data' and not future date. There is no specific start date since the data is dynamic in nature. But end date will be the system date.
Please provide me a code which gives me my desired output. Thanks in advance
Below is the code I'm using:
I'm trying to write a macro where in the final output is a pivot table with counts of transaction, name of processor, along with Follow up date.
Since the data I'm dealing with is in large number, I need only the data till 'current follow up data' and not future date. There is no specific start date since the data is dynamic in nature. But end date will be the system date.
Please provide me a code which gives me my desired output. Thanks in advance
Below is the code I'm using:
VBA Code:
Range("A1:R1").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$R$885").AutoFilter Field:=11, Criteria1:="<>" 'Field here is Follow up date column
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$S$670"), , xlYes).Name = _
"Table1"
Range("A2").Select
ActiveSheet.ListObjects("Table1").Name = "MyData1"
Application.CutCopyMode = False
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"MyData1", Version:=6).CreatePivotTable TableDestination:="Sheet2!R3C1", _
TableName:="PivotTable1", DefaultVersion:=6
Sheets("Sheet2").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Processed by") 'name of individual who processed the transactions
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Follow up Date") 'this is what I'm talking about. This field has future dates too which I don't want in my table.
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Follow Up Status")
.Orientation = xlColumnField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("Transactions"), "Count of Transactions", xlCount
Windows("Book1").Activate
Cells.Select
Selection.Copy
Workbooks(1).Activate
Sheets("My Sheet").Select
Range("A1").Select
ActiveSheet.Paste
Range("C5").Select
Application.WindowState = xlNormal
Workbooks(2).Activate
Application.DisplayAlerts = False
ActiveWindow.Close
Application.DisplayAlerts = True
Windows("Book1").Activate
Application.DisplayAlerts = False
ActiveWindow.Close
Application.DisplayAlerts = True