How to get the caption on a PowerPivot RowItem with VBA

cr731

Well-known Member
Joined
Sep 17, 2010
Messages
611
I have a PowerPivot table and I'm using VBA to try to return the caption on certain RowItems based on the selected cell.

So if my selected cell is in the values area of my PT, I use this

Code:
ActiveCell.PivotCell.RowItems(1).Name

Which gives me the fully qualified value with Table and Column Name such as

[Sales].[Customer].[CustomerName]

However, all I really want is CustomerName.

I know I could do different things with replace or substitute to get it... but I just feel there must be same way...?

I tried

Code:
ActiveCell.PivotCell.RowItems(1).Caption

But this returns blank.

Ultimately, I am trying to return the values in the RowFields of the Pivot based on the selected PivotCell, so if there is some other, better, way, I'm not tied to using the code above.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Not sure it is worth it to try to find a different way. How about:
Code:
Replace(Mid(ActiveCell.PivotCell.RowItems(1).Name,InStrRev(ActiveCell.PivotCell.RowItems(1).Name,".")+2),"]","")
Or, maybe a cleaner way:
Code:
strCaption = ActiveCell.PivotCell.RowItems(1).Name
strCaption = Replace(Mid(strCaption,InStrRev(strCaption,".")+2),"]","")
 
Upvote 0

Forum statistics

Threads
1,225,738
Messages
6,186,725
Members
453,368
Latest member
positivemind

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