Can you display column header as text in pivot?

sryan429

New Member
Joined
Jul 1, 2016
Messages
13
Office Version
  1. 365
Platform
  1. Windows
Hello,
I'm hoping this is an easy one, but am having a difficult time articulating. So sorry and thank you in advance :) I have a list that I'm displaying in tabular form pivot, but I want each of the 2nd data points to be listed in it's own column and use the column header as the field value, NOT a count/sum/etc.

For a generic example, here is the raw data


Excel Workbook
ABCDEFGH
4Raw Data*******
5AnimalColor******
6DogRed******
7CatBlue******
8MouseYellow******
9BirdYellow******
10SquirrelGreen******
11DogYellow******
12CatRed******
13BirdRed******
14BirdOrange******
15BirdBlue******
16********
17Do NOT want tabular. *Looking for colors in column*******
18AnimalColor******
19BirdBlue******
20*Orange******
21*Red******
22*Yellow******
23CatBlue******
24*Red******
25DogRed******
26*Yellow******
27MouseYellow******
28SquirrelGreen******
29Grand Total*******
30********
31When I put Color in columns I see count/sum/etc as options for data, I want to see text instead*******
32********
33Row LabelsBlueGreenOrangeRedYellowGrand Total*
34Bird1*1114*
35Cat1**1*2*
36Dog***112*
37Mouse****11*
38Squirrel*1***1*
39Grand Total2113310*
40********
41What I'd like to see. *Value in column field matching the column header*******
42********
43AnimalBlueGreenOrangeRedYellow**
44BirdBlue*OrangeRedYellow**
45CatBlue**Red***
46Dog***RedYellow**
47Mouse****Yellow**
48Squirrel*Green*****
Sheet1





Any thoughts?
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
As far as I know the only things that can be in the data part of the Pivot Table are numbers.
This code will copy the PT to another worksheet (named ModPT) and convert the numbers (as shown in rows 34-39 above) to the Header Text

Code:
Option Explicit

Sub ShowPTDataWithHeaderValues()

    Dim sWorksheet As String
    Dim sPTSheetName As String
    Dim lLastRow As Long
    Dim lLastCol As Long
    Dim lRowIndex As Long
    Dim lColIndex As Long
    Dim sHeader As String
    
    If ActiveSheet.PivotTables.Count <> 1 Then
        MsgBox "Start this code on a worksheet with one PivotTable ", , "Exiting"
        GoTo End_Sub
    End If
    sWorksheet = "ModPT"
    sPTSheetName = ActiveSheet.Name
    
    On Error Resume Next
    Application.DisplayAlerts = False
    Worksheets(sWorksheet).Delete
    Application.DisplayAlerts = True
    On Error GoTo 0
    Worksheets.Add(After:=Sheets(Sheets.Count)).Name = sWorksheet 'After last
    
    Worksheets(sPTSheetName).Range("A3").CurrentRegion.Copy
    
    With Worksheets("ModPT")
        .Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False
        .Rows("1:1").Delete Shift:=xlUp
        lLastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
        lLastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
        If InStr(.Cells(lLastRow, 1).Value, "Grand Total") > 0 Then lLastRow = lLastRow - 1
        If InStr(.Cells(1, lLastCol).Value, "Grand Total") > 0 Then lLastCol = lLastCol - 1
        
        For lColIndex = 2 To lLastCol
            sHeader = .Cells(1, lColIndex).Value
            For lRowIndex = 2 To lLastRow
                If .Cells(lRowIndex, lColIndex).Value > 0 Then
                    .Cells(lRowIndex, lColIndex).Value = sHeader
                End If
            Next
        Next
        
    End With
    
End_Sub:

End Sub
 
Upvote 0

Forum statistics

Threads
1,216,122
Messages
6,128,963
Members
449,480
Latest member
yesitisasport

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