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):

464654727
dress
464654728
hat
leggings
shirt
shoes
tie
464654729
boots
dress
shirt
464654730
shoes
tie
464654731
leggings
464654732
boots
dress
hat
shirt
464654733
shoes
464654734
tie
464654735
boots
dress
hat
leggings
shirt
shoes
tie
464654736
boots
464654737
dress
464654738
shirt
464654739
shoes
464654740
leggings

<colgroup><col></colgroup><tbody>
</tbody>




Thanks in advance for any help.

MJD

<colgroup><col></colgroup><tbody>
</tbody>
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
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)


A
B
3
Code​
Product​
4
464654727​
dress​
5
464654728​
hat​
6
leggings​
7
shirt​
8
shoes​
9
tie​
10
464654729​
boots​
11
dress​
12
shirt​
13
464654730​
shoes​
14
tie​
15
464654731​
leggings​
16
464654732​
boots​
17
dress​
18
hat​
19
shirt​
20
464654733​
shoes​
21
464654734​
tie​
22
464654735​
boots​
23
dress​
24
hat​
25
leggings​
26
shirt​
27
shoes​
28
tie​
29
464654736​
boots​
30
464654737​
dress​
31
464654738​
shirt​
32
464654739​
shoes​
33
464654740​
leggings​

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,214,921
Messages
6,122,280
Members
449,075
Latest member
staticfluids

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