ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Code for Grouping Text Values in Pivotfield (https://www.excelbanter.com/excel-programming/271817-re-code-grouping-text-values-pivotfield.html)

Keith Young

Code for Grouping Text Values in Pivotfield
 
it can definitely be done manually. It would be the code to do it that I am
looking for.

Thanks

"Dave Peterson" wrote in message
...
I don't think you can group text values like this. Maybe you could add

another
helper column to your raw data and put a formula that "groups" the data

for you.

(Maybe a =vlookup() if you have lots of categories/groups.)


Keith Young wrote:

I have read the help and there is example code for Grouping numbers/date

in
a pivotfield. However, I am interested in grouping specific text values

in
a pivotfield which may not be in any specific order. For example, say a
pivotfield has the following values:

aaa
bbb
ccc
ddd
eee

Using code, I would like to group aaa and ccc and call it GroupX; bbb

and
ddd would be grouped and called GroupY and eee would be in its own group
called GroupZ.

Can this be accomplished somehow using the group method (maybe using an
array of the text values that are to be grouped)?

Thanks, Keith


--

Dave Peterson




Dave Peterson[_3_]

Code for Grouping Text Values in Pivotfield
 
If you mean add the formula via code, you could do something like:

dim LastRow as long
with activesheet
lastrow = .cells(.rows.count,"A").end(xlup).row
.range("j2:J" & lastcell).formula _
= "=vlookup(a2,sheet2!$a$1:$b$99,2,false)"
end with

You could add this before you did your pivottable (adjust the range/sheets
accordingly).

Then modify your pt code to include this column.

(I usually record a macro to get my pivottables. I'm sure your recorded macro
would work as well as my recorded macro <vbg.)



Keith Young wrote:

it can definitely be done manually. It would be the code to do it that I am
looking for.

Thanks

"Dave Peterson" wrote in message
...
I don't think you can group text values like this. Maybe you could add

another
helper column to your raw data and put a formula that "groups" the data

for you.

(Maybe a =vlookup() if you have lots of categories/groups.)


Keith Young wrote:

I have read the help and there is example code for Grouping numbers/date

in
a pivotfield. However, I am interested in grouping specific text values

in
a pivotfield which may not be in any specific order. For example, say a
pivotfield has the following values:

aaa
bbb
ccc
ddd
eee

Using code, I would like to group aaa and ccc and call it GroupX; bbb

and
ddd would be grouped and called GroupY and eee would be in its own group
called GroupZ.

Can this be accomplished somehow using the group method (maybe using an
array of the text values that are to be grouped)?

Thanks, Keith


--

Dave Peterson


--

Dave Peterson



All times are GMT +1. The time now is 03:27 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com