Select rows in pivot table with macro

D

Dolphinv4

Hi,

I have a pivot table as follows:

Doc Tx Amount
123 12 5
124 11 2
125 12 3
(blank) (blank)
Grand Total 10

I need a macro to select the cells in the 2nd row (row just below the
header) - only 3 columns and not the entire row - up to the row just before
the row with (blank).

How do I do that?

Thanks,

Dolphinv4
 
T

Tom Hutchins

Paste this macro into a VBA module in your workbook. Make sure the sheet with
the pivot table is the active sheet, then run the macro (Tools >> Macro >>
Macros >> SelPivotTblCells >> Run).

Sub SelPivotTblCells()
Dim Rng As Range, EndRow As Long, c
Set Rng = ActiveSheet.PivotTables(1).RowRange
Rng.Cells(2, 1).Activate
Set c = Rng.Find(What:="(blank)", LookIn:=xlValues)
If c Is Nothing Then
MsgBox "(blank) not found"
Exit Sub
End If
Range(Rng.Cells(2, 1), Cells(c.Row - 1, 3)).Select
Set Rng = Nothing
Set c = Nothing
End Sub

Hope this helps,

Hutch
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top