Macro to add border to inconsitently sized areas

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
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,224,587
Messages
6,179,738
Members
452,940
Latest member
Lawrenceiow

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