Macro to move column data to new rows under groupings

HeatherF

New Member
Joined
Mar 3, 2020
Messages
32
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I have an excel spreadsheet listing Clients (columns B/C) and the people they're connected to, with 1 row for every connection. So, since Adam (rows 2-4) has 3 relatives in the database, he has 3 rows.

I would like to create a macro that groups rows by Client, so you click on Adam, and rows with his relatives appear beneath him, ideally summing the Jnt LTG columns of himself and his relatives. I tried making a pivot table, but showing all the data associated with each relative created a very long nested outline in column 1.

Is there any way to have the data associated with each relative appear as columns in a single row under the Client header? I've included my existing spreadsheet below. Also, a very manual mockup of what I would like to achieve, based on the first two Clients in the spreadsheet.

Thank you so much!
Heather

Existing Data
Book1
ABCDEFGHIJKL
1ID#AffiliationPref Name w SuffixRating5-yr GivingJnt LTGRelation IdRelation TypeRelation Pref Name w SuffixRelation RatingRelation 5-yr GivingRelation Jnt LTG
210025692AGENTSAdam Kielt9$ 2,750.00$ 24,486.946529599ParentDulcinea Petschelt9$ 100,215.00$ 285,874.13
310025692AGENTSAdam Kielt9$ 2,750.00$ 24,486.9410073058InlawDana Pell8$ -$ 468,390.00
410025692AGENTSAdam Kielt9$ 2,750.00$ 24,486.9410029576ParentHermy Calabry9$ -$ 285,874.13
510025811FYE/AGENTSFelike Pilbury9$ 4,475.00$ 7,015.006406626ParentLarissa Alejandre9$ 3,841.79$ 63,486.54
610025811FYE/AGENTSFelike Pilbury9$ 4,475.00$ 7,015.0010030236SiblingChristiana Cubin$ 650.00$ 1,305.00
710025811FYE/AGENTSFelike Pilbury9$ 4,475.00$ 7,015.0010030996ParentSimeon Bovaird9$ -$ 63,486.54
810025841FYE/AGENTSNeely Beisley$ 2,000.00$ 9,579.306219113UncleJoete Kloss7$ 8,650.00$ 1,318,286.25
910025859FYE/AGENTSWenonah MortCW$ 500.00$ 4,069.975886150ParentWilow Davisson8$ 138,047.03$ 793,357.85
1010025906FYEValentijn PeddoweCW$ -$ 170.8210076736NieceFrederique RandalsonCW$ -$ -
1110025906FYEValentijn PeddoweCW$ -$ 170.8210076742InlawArluene Grocutt6$ 7,500.00$ 1,047,020.00
1210025918FYEGraig FlipsenCW$ 75.90$ 21,275.604123150GrandparentFelicio Buttress9$ -$ 4,356,175.13
1310025918FYEGraig FlipsenCW$ 75.90$ 21,275.6010014561GrandparentTalya Alford6$ -$ 4,356,175.13
1410025918FYEGraig FlipsenCW$ 75.90$ 21,275.6010019897SiblingAlaine HurtonCW$ 49,500.00$ 97,775.00
1510026014AGENTSLoleta Ducarne9$ 2,000.00$ 2,955.00
1610026025FYEFredrika Gettens9$ 1,600.00$ 2,570.0010019980SiblingTheresa ZylbermannU$ 162.50$ 597.50
1710026025FYEFredrika Gettens9$ 1,600.00$ 2,570.006798524ParentTheresa ZylbermannU$ -$ 1,065.00
1810026045FYEKati Wrought$ 4,917.50$ 27,224.9710025813Spouse/PartnerSallyann Blei9$ 4,917.50$ 27,224.97
1910026086FYEHammad Kikke9$ 20,180.31$ 71,055.5510041644SiblingOgdon KaretU$ 175.00$ 985.04
2010026086FYEHammad Kikke9$ 20,180.31$ 71,055.5510030584InlawFlossy Mclie$ -$ 55.00
2110026086FYEHammad Kikke9$ 20,180.31$ 71,055.5510032632SiblingNev Philippart10$ 150.00$ 205.00
2210026121FYEDill Korneichuk7$ 57,500.00$ 96,830.00
2310026178FYEIngemar Barrows7$ 45,131.97$ 80,197.7910079908ParentPippo Duffell$ 465.12$ 3,915.45
2410026178FYEIngemar Barrows7$ 45,131.97$ 80,197.7910059330SiblingHaleigh GodainU$ 40.00$ 160.00
2510028268CREWHeddie HawyesCW$ 850.00$ 3,145.003421331GrandparentTessi GoodluckU$ -$ 9,844.37
2610028268CREWHeddie HawyesCW$ 850.00$ 3,145.0010015662SiblingAudie EasbieCW$ 100.00$ 275.00
2710028268CREWHeddie HawyesCW$ 850.00$ 3,145.006221340ParentBecky Cattle6$ 4,366.41$ 308,554.06
2810030321CREWAngie Lelievre8$ 216,400.00$ 217,585.0010030933ParentJohnathon EdgeU$ -$ 50.00
2910030321CREWAngie Lelievre8$ 216,400.00$ 217,585.0010035814SiblingKlarika Turnpenny10$ 180.00$ 13,505.00
3010030321CREWAngie Lelievre8$ 216,400.00$ 217,585.0010057207SiblingMarla DyballN$ 190.00$ 241.00
Sheet3


Desired Result
Book1
ABCDEFG
1ID#AffiliationPref Name w SuffixRating5-yr GivingJnt LTGSum of Associated LTG
210025692AGENTSAdam Kielt9$ 2,750.00$ 24,486.94$ 1,064,625.20
36529599ParentDulcinea Petschelt9$ 100,215.00$ 285,874.13
410073058InlawDana Pell8$ -$ 468,390.00
510029576ParentHermy Calabry9$ -$ 285,874.13
610025811FYE/AGENTSFelike Pilbury9$ 4,475.00$ 7,015.00$ 135,293.08
76406626ParentLarissa Alejandre9$ 3,841.79$ 63,486.54
810030236SiblingChristiana Cubin$ 650.00$ 1,305.00
910030996ParentSimeon Bovaird9$ -$ 63,486.54
Sheet1
Cell Formulas
RangeFormula
G2,G6G2=SUM(F2:F5)
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
HeatherF

A couple things to start. You don't necessarily need to sort or filter the data to get the sum of each client. You can SUMIFS. =SUMIFS(L:L,C:C,C2)

The UNIQUE function could be used in another table to pull all the client names and then SUMIFS to summarize the values
 
Upvote 0
Solution
HeatherF

A couple things to start. You don't necessarily need to sort or filter the data to get the sum of each client. You can SUMIFS. =SUMIFS(L:L,C:C,C2)

The UNIQUE function could be used in another table to pull all the client names and then SUMIFS to summarize the values
Thank you--that is interesting. It may be the quickest way to go about it. In the example below, I've used your code, and added the Jnt LTG of the Client. But is there a way to roll up rows with identical ID#s under headers so you can expand and collapse each Client?

Book1 (version 1).xlsb
ABCDEFGHIJKLM
1ID#AffiliationPref Name w SuffixRating5-yr GivingJnt LTGRelation IdRelation TypeRelation Pref Name w SuffixRelation RatingRelation 5-yr GivingRelation Jnt LTGTOTAL Associated LTG
210025692AGENTSAdam Kielt9$ 2,750.00$ 24,486.946529599ParentDulcinea Petschelt9$ 100,215.00$ 285,874.13$ 1,064,625.20
310025692AGENTSAdam Kielt9$ 2,750.00$ 24,486.9410073058InlawDana Pell8$ -$ 468,390.00$ 1,064,625.20
410025692AGENTSAdam Kielt9$ 2,750.00$ 24,486.9410029576ParentHermy Calabry9$ -$ 285,874.13$ 1,064,625.20
510025811FYEFelike Pilbury9$ 4,475.00$ 7,015.006406626ParentLarissa Alejandre9$ 3,841.79$ 63,486.54$ 135,293.08
610025811FYEFelike Pilbury9$ 4,475.00$ 7,015.0010030236SiblingChristiana Cooch$ 650.00$ 1,305.00$ 135,293.08
710025811FYEFelike Pilbury9$ 4,475.00$ 7,015.0010030996ParentSimeon Bovaird9$ -$ 63,486.54$ 135,293.08
Sheet4
Cell Formulas
RangeFormula
M2:M7M2=SUMIFS(L:L,C:C,C2)+F2
 
Upvote 0
I thought I'd found an answer. I used the subtotal dialog to COUNT at every change in the Pref Name field and add the subtotal to column N, but I don't know why the count is O. Shouldn't it be 3 for the first person?

Book1
ABCDEFGHIJKLMN
1ID#AffiliationPref Name w SuffixRating5-yr GivingJnt LTGRelation IdRelation TypeRelation Pref Name w SuffixRelation RatingRelation 5-yr GivingRelation Jnt LTGTOTAL Associated LTGTOTAL Associated Prospects
2Grand Count0
3Adam Kielt Count0
410025692AGENTSAdam Kielt9$ 2,750.00$ 24,486.946529599ParentDulcinea Petschelt9$ 100,215.00$ 285,874.13$ 1,064,625.20
510025692AGENTSAdam Kielt9$ 2,750.00$ 24,486.9410073058InlawDana Pell8$ -$ 468,390.00$ 1,064,625.20
610025692AGENTSAdam Kielt9$ 2,750.00$ 24,486.9410029576ParentHermy Calabry9$ -$ 285,874.13$ 1,064,625.20
7Felike Pilbury Count0
810025811FYEFelike Pilbury9$ 4,475.00$ 7,015.006406626ParentLarissa Alejandre9$ 3,841.79$ 63,486.54$ 200,084.62
910025811AGENTSFelike Pilbury9$ 4,475.00$ 7,015.006406626ParentLarissa Alejandre9$ 3,841.79$ 63,486.54$ 200,084.62
1010025811FYEFelike Pilbury9$ 4,475.00$ 7,015.0010030236SiblingChristiana Cooch$ 650.00$ 1,305.00$ 200,084.62
1110025811AGENTSFelike Pilbury9$ 4,475.00$ 7,015.0010030236SiblingChristiana Cooch$ 650.00$ 1,305.00$ 200,084.62
1210025811AGENTSFelike Pilbury9$ 4,475.00$ 7,015.0010030996ParentSimeon Bovaird9$ -$ 63,486.54$ 200,084.62
13Neely Beisley Count0
1410025841AGENTSNeely Beisley$ 2,000.00$ 9,579.306219113UncleJoete Kloss7$ 8,650.00$ 1,318,286.25$ 1,327,865.55
Sheet2
Cell Formulas
RangeFormula
N2N2=SUBTOTAL(3,N4:N14)
N3N3=SUBTOTAL(3,N4:N6)
M14,M8:M12,M4:M6M4=SUMIFS(L:L,C:C,C4)+F4
N7N7=SUBTOTAL(3,N8:N12)
N13N13=SUBTOTAL(3,N14:N14)
 
Upvote 0
You would probably want to use Countifs using the agent's name column to count and the relative's name to not equal the agent's name.

Concerning rolling up the list without using a pivot table... A macro could do that. It would have to sort, then go and group all the agents together. The formula in the Jnt total column could be restricted to only show if the Agent's name doesn't equal the relative name. A macro could be created in a couple hours to get it right.
 
Upvote 0

Forum statistics

Threads
1,215,345
Messages
6,124,408
Members
449,157
Latest member
mytux

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