Is the active cell in a pivot table row field

Ziggy12

Active Member
Joined
Jun 26, 2002
Messages
365
Hi there
How do I tell if the active cell is in a row field and which one if there is more than one.

Is there a way to returnt he name of the row field the active cell is in?

cheers
ziggy
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Look at using a Function Called Address that might help you.
 
Upvote 0
This thread is somewhat dated, but here is a function that might
still be of use to you, or helpful to someone else who finds this thread.

Code:
Function isPTRowRange(c As Range) As Boolean
    Dim varRet As Variant
    On Error Resume Next
    varRet = Intersect(c, c.PivotCell.Parent.RowRange)
    isPTRowRange = Err.Number = 0
End Function

Call the function with ActiveCell or any Cell Reference...
Code:
Sub TEST()
    MsgBox isPTRowRange(ActiveCell)
End Sub
 
Upvote 0
Thanks for that
I solved it with this. If the active cell is in a row feild it returns the feild name but also return the feild name if the name itself is the active cell so turned of any action with the bold bit below.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error GoTo ErrorHandler

Dim SepMonth As String, CareType As String, ServiceArea As String, ClinUnit As String
Dim UnitPT As PivotTable, WardPT As PivotTable, PT As PivotTable

Set UnitPT = Worksheets("LoS Drill Down").Range("A4").PivotTable
Set WardPT = Worksheets("LoS Drill Down").Range("M4").PivotTable
Set PT = ActiveCell.PivotTable

If Application.Range(ActiveCell.Address).PivotCell.PivotCellType <> xlPivotCellValue Then
If PT.Name = "UnitPT" And ActiveCell.PivotField.Name = "Clin Unit" And ActiveCell.Value <> "Clin Unit" Then
WardPT.PivotFields("Service Area").CurrentPage = UnitPT.PivotFields("Service Area").CurrentPage.Name
WardPT.PivotFields("Care Type").CurrentPage = UnitPT.PivotFields("Care TYpe").CurrentPage.Name
WardPT.PivotFields("Sep Month").CurrentPage = UnitPT.PivotFields("Sep Month").CurrentPage.Name
WardPT.PivotFields("Clin Unit").CurrentPage = ActiveCell.Value
Application.Goto Reference:=Range("L1"), Scroll:=True
End If
End If
End
ErrorHandler: If PT Is Nothing Then End
End Sub
 
Upvote 0
To return the name of the rowfield
MsgBox Application.Range(ActiveCell.Address).PivotCell.RowItems.Item(1)
 
Upvote 0
Hi again Ziggy,

I don't think that's correct. That code will return the associated PivotItem for the first RowField in the PivotTable, but not the RowField name itself.

That expression (if returning a pivot item is the desired result), could be simplified to....
Code:
   MsgBox ActiveCell.PivotCell.RowItems.Item(1)

Note that if you have multiple row fields, this will just return the row item associated with the first row field, not necessarily the row field on the same row as the active cell in a Pivot with Compact Form layout.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,845
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top