Combining PivotTable Rows from Headers

MarkJamesDavies

New Member
Joined
Jan 30, 2015
Messages
12
Hello,

This is my first post, please be patient. I will put as much detail as possible.

I'm trying to export all of the data between headers from a pivot table into 1 cell but the items in between are inconsistent in terms of their cell creation. I tried the "=CONCATENATE" function however, due to the cells being inconsistent, it's very difficult to do.

Is it possible someone could help me with this problem? I visit this site a lot and has been wonderful.

Table Example (imagine this table in a 1 column pivot table with the numbers in a header):

[TABLE="width: 155"]
<colgroup><col></colgroup><tbody>[TR]
[TD="align: center"]464654727
[/TD]
[/TR]
[TR]
[TD="align: center"]dress[/TD]
[/TR]
[TR]
[TD="align: center"]464654728
[/TD]
[/TR]
[TR]
[TD="align: center"]hat[/TD]
[/TR]
[TR]
[TD="align: center"]leggings[/TD]
[/TR]
[TR]
[TD="align: center"]shirt[/TD]
[/TR]
[TR]
[TD="align: center"]shoes[/TD]
[/TR]
[TR]
[TD="align: center"]tie[/TD]
[/TR]
[TR]
[TD="align: center"]464654729[/TD]
[/TR]
[TR]
[TD="align: center"]boots[/TD]
[/TR]
[TR]
[TD="align: center"]dress[/TD]
[/TR]
[TR]
[TD="align: center"]shirt[/TD]
[/TR]
[TR]
[TD="align: center"]464654730[/TD]
[/TR]
[TR]
[TD="align: center"]shoes[/TD]
[/TR]
[TR]
[TD="align: center"]tie[/TD]
[/TR]
[TR]
[TD="align: center"]464654731[/TD]
[/TR]
[TR]
[TD="align: center"]leggings[/TD]
[/TR]
[TR]
[TD="align: center"]464654732[/TD]
[/TR]
[TR]
[TD="align: center"]boots[/TD]
[/TR]
[TR]
[TD="align: center"]dress[/TD]
[/TR]
[TR]
[TD="align: center"]hat[/TD]
[/TR]
[TR]
[TD="align: center"]shirt[/TD]
[/TR]
[TR]
[TD="align: center"]464654733[/TD]
[/TR]
[TR]
[TD="align: center"]shoes[/TD]
[/TR]
[TR]
[TD="align: center"]464654734[/TD]
[/TR]
[TR]
[TD="align: center"]tie[/TD]
[/TR]
[TR]
[TD="align: center"]464654735[/TD]
[/TR]
[TR]
[TD="align: center"]boots[/TD]
[/TR]
[TR]
[TD="align: center"]dress[/TD]
[/TR]
[TR]
[TD="align: center"]hat[/TD]
[/TR]
[TR]
[TD="align: center"]leggings[/TD]
[/TR]
[TR]
[TD="align: center"]shirt[/TD]
[/TR]
[TR]
[TD="align: center"]shoes[/TD]
[/TR]
[TR]
[TD="align: center"]tie[/TD]
[/TR]
[TR]
[TD="align: center"]464654736[/TD]
[/TR]
[TR]
[TD="align: center"]boots[/TD]
[/TR]
[TR]
[TD="align: center"]464654737[/TD]
[/TR]
[TR]
[TD="align: center"]dress[/TD]
[/TR]
[TR]
[TD="align: center"]464654738[/TD]
[/TR]
[TR]
[TD="align: center"]shirt[/TD]
[/TR]
[TR]
[TD="align: center"]464654739[/TD]
[/TR]
[TR]
[TD="align: center"]shoes[/TD]
[/TR]
[TR]
[TD="align: center"]464654740[/TD]
[/TR]
[TR]
[TD="align: center"]leggings[/TD]
[/TR]
</tbody>[/TABLE]




[TABLE="width: 155"]
<colgroup><col></colgroup><tbody>[TR]
[TD][/TD]
[/TR]
[TR]
[TD]Thanks in advance for any help.

MJD
[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi,
just curious, what do you want to see into 'one cell'?
maybe you could post a very small sample of your raw data prior to the PT and what you wish to achieve as final result, such might allow members to give you better feedback.
To post small sample please read instructions in my signature below.
 
Upvote 0
I think that, in fact, your Pivot Table has 2 columns, i.e., two different fields

Try to change the Pivot Table layout to Tabular Form

Pivot Tables Tools > Design > in the Layout Group click Report Layout and pick Tabular Form

Probably you will see something like this (maybe with different field names)


[Table="class: grid"][tr][td] [/td][td]
A
[/td][td]
B
[/td][/tr]
[tr][td]
3
[/td][td]
Code​
[/td][td]
Product​
[/td][/tr]

[tr][td]
4
[/td][td]
464654727​
[/td][td]
dress​
[/td][/tr]

[tr][td]
5
[/td][td]
464654728​
[/td][td]
hat​
[/td][/tr]

[tr][td]
6
[/td][td] [/td][td]
leggings​
[/td][/tr]

[tr][td]
7
[/td][td] [/td][td]
shirt​
[/td][/tr]

[tr][td]
8
[/td][td] [/td][td]
shoes​
[/td][/tr]

[tr][td]
9
[/td][td] [/td][td]
tie​
[/td][/tr]

[tr][td]
10
[/td][td]
464654729​
[/td][td]
boots​
[/td][/tr]

[tr][td]
11
[/td][td] [/td][td]
dress​
[/td][/tr]

[tr][td]
12
[/td][td] [/td][td]
shirt​
[/td][/tr]

[tr][td]
13
[/td][td]
464654730​
[/td][td]
shoes​
[/td][/tr]

[tr][td]
14
[/td][td] [/td][td]
tie​
[/td][/tr]

[tr][td]
15
[/td][td]
464654731​
[/td][td]
leggings​
[/td][/tr]

[tr][td]
16
[/td][td]
464654732​
[/td][td]
boots​
[/td][/tr]

[tr][td]
17
[/td][td] [/td][td]
dress​
[/td][/tr]

[tr][td]
18
[/td][td] [/td][td]
hat​
[/td][/tr]

[tr][td]
19
[/td][td] [/td][td]
shirt​
[/td][/tr]

[tr][td]
20
[/td][td]
464654733​
[/td][td]
shoes​
[/td][/tr]

[tr][td]
21
[/td][td]
464654734​
[/td][td]
tie​
[/td][/tr]

[tr][td]
22
[/td][td]
464654735​
[/td][td]
boots​
[/td][/tr]

[tr][td]
23
[/td][td] [/td][td]
dress​
[/td][/tr]

[tr][td]
24
[/td][td] [/td][td]
hat​
[/td][/tr]

[tr][td]
25
[/td][td] [/td][td]
leggings​
[/td][/tr]

[tr][td]
26
[/td][td] [/td][td]
shirt​
[/td][/tr]

[tr][td]
27
[/td][td] [/td][td]
shoes​
[/td][/tr]

[tr][td]
28
[/td][td] [/td][td]
tie​
[/td][/tr]

[tr][td]
29
[/td][td]
464654736​
[/td][td]
boots​
[/td][/tr]

[tr][td]
30
[/td][td]
464654737​
[/td][td]
dress​
[/td][/tr]

[tr][td]
31
[/td][td]
464654738​
[/td][td]
shirt​
[/td][/tr]

[tr][td]
32
[/td][td]
464654739​
[/td][td]
shoes​
[/td][/tr]

[tr][td]
33
[/td][td]
464654740​
[/td][td]
leggings​
[/td][/tr]
[/table]


Which cells do you want to concatenate?

M.
 
Upvote 0
Hello, thank you for the reply.

I want to concatenate, for example, B5:B9 however, I want to be able to run the formula all the way down so the Code's product is in 1 cell.

So, in theory, if the A column has data in, the B columns data will be concatenated all the way until the next A cell has data in.

Example:
Excel 2012
ABCD
1AB
23CodeProductconcatenated
34464654727dressdress
45464654728hathat tie leggings shirt shoes
56leggings
67shirt
78shoes
89tie
910464654729bootsboots dress shirt
1011dress
1112shirt
1213464654730shoesshoes tie
1314tie
1415464654731leggingsleggings
1516464654732bootsboots dress hat shirt
1617dress
1718hat
1819shirt
1920464654733shoesshoes
2021464654734tietie
2122464654735bootsboots dress hat leggings shirt shoes tie
2223dress
2324hat
2425leggings
2526shirt
2627shoes
2728tie
2829464654736bootsboots
2930464654737dressdress
3031464654738shirtshirt
3132464654739shoesshoes
3233464654740leggingsleggings
Sheet1
Cell Formulas
RangeFormula
D4=CONCATENATE(C4," ", C8, " ",C5, " ", C6, " ", C7)
D9=CONCATENATE(C9," ",C10, " ",C11, " ")
D12=CONCATENATE(C12, " ",C13)
D15=CONCATENATE(C15, " ",C16, " ",C17, " ",C18, " ")
D21=CONCATENATE(C21, " ",C22, " ",C23, " ",C24, " ",C25, " ", C26, " ",C27)
 
Upvote 0
Please see my reply to the other user,

Thanks a lot of the HTML guide, amazing job my friend!! Really simple to use also.

Thanks again, hope you can help me.

MJD
 
Upvote 0
Hello, here is one option if you can use the ACONCAT, search other posts for details, but here is the code from one post (workbook will needs to be saved as xlsm)

ACONCAT is a work-alike written in VBA...

Function aconcat(a As Variant, Optional sep As String = "") As String
' Harlan Grove, Mar 2002
Dim y As Variant
If TypeOf a Is Range Then
For Each y In a.Cells
aconcat = aconcat & y.Value & sep
Next y
ElseIf IsArray(a) Then
For Each y In a
aconcat = aconcat & y & sep
Next y
Else
aconcat = aconcat & a & sep
End If
aconcat = Left(aconcat, Len(aconcat) - Len(sep))
End Function

The formula would then be this, data starting in A3:

=IF(A3<>A2,aconcat(B3:INDIRECT("B"&ROWS($A$1:A3)+COUNTIF($A$3:$A$32,A3)-1)," "),"")
 
Upvote 0
Hello Joyner,

I just tried this formula and only #NAME? comes? Am I doing something wrong?

Apologies in advance if I am.

HTML:


Excel 2012
ABCD
1CodeProduct
2464654727dress#NAME?
3464654728hat
4leggings
5shirt
6shoes
7tie
8464654729boots
9dress
10shirt
11464654730shoes
12tie
13464654731leggings
14464654732boots
15dress
16hat
17shirt
18464654733shoes
19464654734tie
20464654735boots
21dress
22hat
23leggings
24shirt
25shoes
26tie
27464654736boots
28464654737dress
29464654738shirt
30464654739shoes
31464654740legging
Sheet1
Cell Formulas
RangeFormula
D2=IF(A3<>A2,aconcat(B3:INDIRECT("B"&ROWS($A$1:A3)+COUNTIF($A$3:$A$32,A3)-1)," "),"")
 
Upvote 0
Hello, did you put the aconcat code in a module? I am guessing that is the problem since you are getting the #NAME error, so Excel doesn't recognize a name in the formula. If not, the code needs to be copied into a vba/code module, so in for file click Alt F11, go to Insert; Module and copy the code in there and save.

AND...sorry I forgot to mention an important part, for my formula to work you need to "Repeat All Item Labels" (if you have Excel 2010 or later) - click in the Code column, and on the Design Tab, Layout group all the way to the left, Report Layout, and "Repeat All Item Labels". If you don't have at least 2010, we would need to fill blank on the data versus the pivot table, or rewrite the formula to use the blanks instead of the repeating code numbers.

The formula should work, but for the original formula the start the data was in A3 versus A2, For data starting in A2 use this instead:

=IF(A2<>A1,aconcat(B2:INDIRECT("B"&ROWS($A$1:A2)+COUNTIF($A$2:$A$31,A2)-1)," "),"")
 
Upvote 0
Hello Joyner,

Thank you for your assistance again,

I've attempted the above however, I failed.

When I try to run the module, it states:

"Compile error:

Expected: line number or label or statement or end of statement"

I'm using Excel 2007 but I've also tried it on Excel 2013 also but no success here.

I've personally created macro's and modules to do other things in Excel but I just cannot get this to run correctly.

Thanks in advance for any help,

MJD.
 
Upvote 0
I can't tell you what that problem may be. I just tried to copy the code I gave you, to a new module and it works fine. The only thing I can think is that somehow you didn't copy and paste all of the code. I don't think there would be a reason why it would work on my computer and not on yours.

I would suggest you copy the code again to a module, then retry the formula.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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