Using Macro to Alter Pivot Table

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible to get a macro to take the Content of a cell and use that to
alter a pivot table.

For example:

"In the pivot table the different criteria for Page are 1;2;3. Usualy it
shows the data regarding to 1;2;3. In another datasheet I typ 1.

"Is it possible to make the Pivot Table show only the data regarding 1;
instead of 1;2;3 by use of a macro?"

Thanks in Advance!
 
You can use an event procedure to change the page field item.
Select the sheet on which you'll type the number
Right-click the sheet tab, and choose View Code
Where the cursor is flashing, paste the following code:

'==========================
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$K$2" Then
Sheets("Pivot").PivotTables("PivotTable1") _
.PivotFields("Year").CurrentPage = Target.Value
End If
End Sub
'======================================

Replace the cell reference, the sheet name, and the field name, to match
the names in your workbook.
 
Back
Top