Benlangrick
New Member
- Joined
- Jul 4, 2011
- Messages
- 1
I have created a macro to create a pivot table from some raw data. This pivot table will show individual mobile phones numbers, with additional information about each number listed.
I would like to be able to 'box off' each individual number and it's relevant information with a border, but the size of the area that needs 'boxing off' will be different for each number.
This macro will need to be used on a various workbooks each with different names also.
Here is the code i am using to create the pivot table
Sub Tariff()
'
' Tariff Macro
' Tariff + Services
'
' Keyboard Shortcut: Ctrl+t
'
Selection.End(xlUp).Select
Selection.End(xlToLeft).Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
Selection.CurrentRegion).CreatePivotTable TableDestination:="", _
TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("Invoice Month").Caption = _
"Date"
ActiveSheet.PivotTables("PivotTable1").PivotFields("Mobile Phone").Caption = _
"MPN"
ActiveSheet.PivotTables("PivotTable1").PivotFields("Tariff Description"). _
Caption = "Tariff"
ActiveSheet.PivotTables("PivotTable1").PivotFields("Service Description"). _
Caption = "Services"
ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:=Array("MPN", _
"Tariff", "Services"), ColumnFields:="Date"
With ActiveSheet.PivotTables("PivotTable1").PivotFields("SumOfInvoiced total")
.Orientation = xlDataField
.Caption = "Cost"
.NumberFormat = "£#,##0.00"
End With
ActiveSheet.PivotTables("PivotTable1").PivotSelect "", xlDataAndLabel, True
ActiveSheet.PivotTables("PivotTable1").Format xlReport4
Range("F10").Select
End Sub
Also, one of the options in the pivot table is 'invoice date'. I would like the macro to select only the most recent date, but can't work out how to make it work.
Thanks a lot - let me know if you need to know anything else
I would like to be able to 'box off' each individual number and it's relevant information with a border, but the size of the area that needs 'boxing off' will be different for each number.
This macro will need to be used on a various workbooks each with different names also.
Here is the code i am using to create the pivot table
Sub Tariff()
'
' Tariff Macro
' Tariff + Services
'
' Keyboard Shortcut: Ctrl+t
'
Selection.End(xlUp).Select
Selection.End(xlToLeft).Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
Selection.CurrentRegion).CreatePivotTable TableDestination:="", _
TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("Invoice Month").Caption = _
"Date"
ActiveSheet.PivotTables("PivotTable1").PivotFields("Mobile Phone").Caption = _
"MPN"
ActiveSheet.PivotTables("PivotTable1").PivotFields("Tariff Description"). _
Caption = "Tariff"
ActiveSheet.PivotTables("PivotTable1").PivotFields("Service Description"). _
Caption = "Services"
ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:=Array("MPN", _
"Tariff", "Services"), ColumnFields:="Date"
With ActiveSheet.PivotTables("PivotTable1").PivotFields("SumOfInvoiced total")
.Orientation = xlDataField
.Caption = "Cost"
.NumberFormat = "£#,##0.00"
End With
ActiveSheet.PivotTables("PivotTable1").PivotSelect "", xlDataAndLabel, True
ActiveSheet.PivotTables("PivotTable1").Format xlReport4
Range("F10").Select
End Sub
Also, one of the options in the pivot table is 'invoice date'. I would like the macro to select only the most recent date, but can't work out how to make it work.
Thanks a lot - let me know if you need to know anything else