I use Ctrl+[
all the time to go to the precedents of the ActiveCell. The SourceData for a PivotTable isn’t a precedent, but wouldn’t it be nice if there was a shortcut to go there? Yes, it would.
Until now, if I wanted to see the SourceData for a PivotTable, I would use Alt, J, T, I, D
to activate the Ribbon control for changing the source data (PivotTable Tools – Options – Change Data Source – Change Data Source). That would open the Change PivotTable Data Source dialog. The focus on that dialog is a RefEdit control so Excel navigates to the data. I don’t actually want to change it, though, so I hit ESC and it takes me back to the PivotTable. But I make a note of where it is and I use Ctrl+G
or simply navigate to where it is.
I decide to repurpose Ctrl+[
to do the deed.
1 2 3 4 5 6 7 8 9 |
Public Sub SelectPrecedents() gclsAppEvents.AddLog "^[", "SelectPrecedents" On Error Resume Next Selection.DirectPrecedents.Select Application.Goto ActiveCell.PivotTable.SourceData End Sub |
First, I recorded a macro to see what happens when I press Ctrl+[
. That became the first line after the error handler. Rather than doing a bunch of checking to see whether the ActiveCell was in a PivotTable, whether the PivotTable source was a Range, and a bunch of other stuff that I can’t even predict, I just attempt to Goto the SourceData. If it works, then it was possible. If there’s some reason I can’t, it just fails silently.