Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Viewing the Specific Source Data Rows for a PivotTable Summary Value

PivotTable Tips

Viewing the Specific Source Data Rows for a PivotTable Summary Value

by  SkipVought  Posted    (Edited  )
There is a handy way to view the specific source data rows that correspond to the PivotTable summary value in a PivotTable.

You simply DOUBLE-CLICK any summary value, and a new sheet is inserted into your workbook with the specific source data rows that correspond to the PivotTable summary value the you DOUBLE-CLICKED. Its that simple!

If you do that a few times, you can get tired of having to DELETE these newly inserted sheets.

So here's how to 'fix' that problem, so that when you select off that newly inserted sheet to another sheet, it will automatically be deleted!

CAVEAT: Every sheet in your workbook that you want to keep, must have a Sheet Name that does not begin with [highlight]Sheet[/highlight]
!!!

Here are the steps to getting there...
[tt]
1. alt+F11 toggles between the sheet and the VB Editor, where macros are stored.

2. In the VB Editor, ctr+R activates the Project Explorer

3. In the Project Explorer, Right-Click the ThisWorkbook Microsoft Excel Object and select View Code.

4. Paste this code in that code window
Code:
Option Explicit

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
    Application.DisplayAlerts = False
    If Left(Sh.Name, 5) = "Sheet" Then Sh.Delete
    Application.DisplayAlerts = False
End Sub
5. SAVE the workbook as a macro-enabled workbook if you have Excel 2007+
[/tt]

If you want to be able to keep the Sheet to return to it without changing the Sheet Name, kind of a temporary thing, then here's a method for that.

Procedurally, make any selection in the sheet other than selecting all the data. This modified code will allow you to keep that un-renamed sheet. When you want it deleted, use the Select Current Region or ctr+A icon to select all the data.
Code:
Option Explicit[b]
Public LastSelection As String[/b]

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
    Application.DisplayAlerts = False
    If Left(Sh.Name, 5) = "Sheet" Then[b]
        If LastSelection = Sh.[A1].CurrentRegion.Address[/b] Then Sh.Delete[b]
        LastSelection = ""[/b]
    End If
    Application.DisplayAlerts = False
End Sub
[b]
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    LastSelection = Target.Address
End Sub[/b]
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top