michaela18
Technical User
Hi,I am trying to get this to work automatically. It is a pivot table and on the top there is a report filter field "Name of Person". I run a report everytime and I always choose different names, like Bob and Gary, or Cindy and Sonia. So everytime I select a diff name I want the names selected to appear as the title in cell A1 so when I print it, I can see what I chose. But it isn't working. Help please.
Private Sub Automatic_Event(ByVal Target As Range)
If Intersect(Target, PivotFields("Name of Person")) Is Nothing Then
Exit Sub
'==========================================================================='
'Inserts the Title and Formats it '
Else
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Name of Person")
For i = 1 To .PivotItems.Count
If .PivotItems(i).VisibleFields = True Then
ActiveSheet.Rows("1:2").Insert Shift:=xlDown
Cells(1, 1).Value = "Name:" & "," & PivotItems(i)
Cells(1, 1).FontSize = 13
Cells(1, 1).Font.Bold = True
Range("A1:d1").HorizontalAlignment = xlCenterAcrossSelection
.PrintTitleRows = "$1:$6"
Next i
End With
End If
'==========================================================================='
Dim FileSaveAsName As Variant
FileSaveAsName = Application.GetSaveAsFilename( _
InitialFileName:="Name"
FileFilter:="Excel Macro-Enabled Workbook (*.xls), *.xls")
If fileSaveName <> "" Then ActiveWorkbook.SaveAs fileSaveName
End Sub
Private Sub Automatic_Event(ByVal Target As Range)
If Intersect(Target, PivotFields("Name of Person")) Is Nothing Then
Exit Sub
'==========================================================================='
'Inserts the Title and Formats it '
Else
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Name of Person")
For i = 1 To .PivotItems.Count
If .PivotItems(i).VisibleFields = True Then
ActiveSheet.Rows("1:2").Insert Shift:=xlDown
Cells(1, 1).Value = "Name:" & "," & PivotItems(i)
Cells(1, 1).FontSize = 13
Cells(1, 1).Font.Bold = True
Range("A1:d1").HorizontalAlignment = xlCenterAcrossSelection
.PrintTitleRows = "$1:$6"
Next i
End With
End If
'==========================================================================='
Dim FileSaveAsName As Variant
FileSaveAsName = Application.GetSaveAsFilename( _
InitialFileName:="Name"
FileFilter:="Excel Macro-Enabled Workbook (*.xls), *.xls")
If fileSaveName <> "" Then ActiveWorkbook.SaveAs fileSaveName
End Sub