Create list of last(family) names when parents have children in more than 1 class

Hart

Board Regular
Joined
Jan 2, 2005
Messages
78
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
MASTER CLASS LIST Nov 12 2024.xlsm
BCDEFGHILMN
1Last NameFirst NameDOBGenderPhoneParentsPHNAddressNamePENGrade
Families


I would like to create a sheet containing the last (family) name of all students in a school as well the grade. The family name will appear in ColumnA and the Grade in ColumnB. Additionally, a family may have more than 1 student in a class (twins or triplets) and if so, the resulting grade cell would also include the number of children in the grade, for example 5(2x) twins or 5(3x) triplets etc. The information is contained in a table (above). The determining factor when there are multiple identical last names is the "contact field" contents - i.e. same parent/guardian. The table can be sorted in any sequence but will likely be by last name, contact and grade. Ideally, after 55 (or so) family names and grades, the macro will then start populating at row 1, columns D and E, Then Columns G and H. After G and H are filled, back to column a&B with a page break. Continue until the table is processed.

Resulting output sheet called "families":
ColumnA ColumnB
Name Grade

Anderson 3
Brown 3 x 2, 4, 5 (for 2 students in grade 3) one in grade 4, one in grade 5
etc.....
Many thanks in advance,
Hart
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
As you are using (also) Microsoft 365 - have you been thinking of a new function GroupBy ? Something like:
Excel Formula:
=GROUPBY(HSTACK(Table1[[#All],[Last Name]],Table1[[#All],[Parents]]),Table1[[#All],[Grade]],ARRAYTOTEXT,3,0)

Well, it does not list Anderson as 3x2; 4 , just simple 3; 3; 4 but may be it would be enough? If not lambda function could be used instead of ARRAYTOTEXT
PS. in your case the output can be with commas not semicolons - it depends on system local settings.

I used HSTACK inside, because there are 2 Scott families in my school :-)
Zeszyt1
ABCDEFGHIJKLMNOPQR
1Last NameFirst NameDOBGenderPhoneParentsPHNAddressColumn1Column2NamePENGradeLast NameParentsGrade
2AndersonPeterMaria, John3AndersonMaria, John3; 3; 4
3AndersonAnneMaria, John3BrownAnna, Peter3
4AndersonIanMaria, John4ScottMaria, Jack4; 5
5BrownKevinAnna, Peter3ScottMaria, John6
6ScottLilyMaria, Jack4
7ScottPeterMaria, Jack5
8ScottPeterMaria, John6
9
Arkusz1
Cell Formulas
RangeFormula
O1:Q5O1=GROUPBY(HSTACK(Table1[[#All],[Last Name]],Table1[[#All],[Parents]]),Table1[[#All],[Grade]],ARRAYTOTEXT,3,0)
Dynamic array formulas.
 
Upvote 0
Solution
As you are using (also) Microsoft 365 - have you been thinking of a new function GroupBy ? Something like:
Excel Formula:
=GROUPBY(HSTACK(Table1[[#All],[Last Name]],Table1[[#All],[Parents]]),Table1[[#All],[Grade]],ARRAYTOTEXT,3,0)

Well, it does not list Anderson as 3x2; 4 , just simple 3; 3; 4 but may be it would be enough? If not lambda function could be used instead of ARRAYTOTEXT
PS. in your case the output can be with commas not semicolons - it depends on system local settings.

I used HSTACK inside, because there are 2 Scott families in my school :-)
Zeszyt1
ABCDEFGHIJKLMNOPQR
1Last NameFirst NameDOBGenderPhoneParentsPHNAddressColumn1Column2NamePENGradeLast NameParentsGrade
2AndersonPeterMaria, John3AndersonMaria, John3; 3; 4
3AndersonAnneMaria, John3BrownAnna, Peter3
4AndersonIanMaria, John4ScottMaria, Jack4; 5
5BrownKevinAnna, Peter3ScottMaria, John6
6ScottLilyMaria, Jack4
7ScottPeterMaria, Jack5
8ScottPeterMaria, John6
9
Arkusz1
Cell Formulas
RangeFormula
O1:Q5O1=GROUPBY(HSTACK(Table1[[#All],[Last Name]],Table1[[#All],[Parents]]),Table1[[#All],[Grade]],ARRAYTOTEXT,3,0)
Dynamic array formulas.
I haven't even looked at the groupby function but will now. This is perfect. Thanks!
 
Upvote 0
If you are not going to be moving the columns around then you could compact that a bit.
I am assuming 'Last Name' is the 1st column in the table and 'Parents' is the 6th column. Adjust the 1, 6 in the formula if that is not correct.
Excel Formula:
=GROUPBY(CHOOSECOLS(Table1[#All],1,6),Table1[[#All],[Grade]],ARRAYTOTEXT,3,0)
 
Upvote 0
If you are not going to be moving the columns around then you could compact that a bit.
I am assuming 'Last Name' is the 1st column in the table and 'Parents' is the 6th column. Adjust the 1, 6 in the formula if that is not correct.
Excel Formula:
=GROUPBY(CHOOSECOLS(Table1[#All],1,6),Table1[[#All],[Grade]],ARRAYTOTEXT,3,0)
Is there a way for this function to ignore grades which contain an alpha character? At this point, I have to create a separate sheet with grades with numeric values only.
 
Upvote 0
As you are using (also) Microsoft 365 - have you been thinking of a new function GroupBy ? Something like:
Excel Formula:
=GROUPBY(HSTACK(Table1[[#All],[Last Name]],Table1[[#All],[Parents]]),Table1[[#All],[Grade]],ARRAYTOTEXT,3,0)

Well, it does not list Anderson as 3x2; 4 , just simple 3; 3; 4 but may be it would be enough? If not lambda function could be used instead of ARRAYTOTEXT
PS. in your case the output can be with commas not semicolons - it depends on system local settings.

I used HSTACK inside, because there are 2 Scott families in my school :-)
Zeszyt1
ABCDEFGHIJKLMNOPQR
1Last NameFirst NameDOBGenderPhoneParentsPHNAddressColumn1Column2NamePENGradeLast NameParentsGrade
2AndersonPeterMaria, John3AndersonMaria, John3; 3; 4
3AndersonAnneMaria, John3BrownAnna, Peter3
4AndersonIanMaria, John4ScottMaria, Jack4; 5
5BrownKevinAnna, Peter3ScottMaria, John6
6ScottLilyMaria, Jack4
7ScottPeterMaria, Jack5
8ScottPeterMaria, John6
9
Arkusz1
Cell Formulas
RangeFormula
O1:Q5O1=GROUPBY(HSTACK(Table1[[#All],[Last Name]],Table1[[#All],[Parents]]),Table1[[#All],[Grade]],ARRAYTOTEXT,3,0)
Dynamic array formulas.
Is there a way for this function to ignore grades which contain an alpha character? At this point, I have to create a separate sheet with grades with numeric values only.
 
Upvote 0
Simple modification of my formula (at the cost of automatic headers) could be:

Excel Formula:
=GROUPBY(FILTER(HSTACK(Table1[Last Name],Table1[Parents]),ISNUMBER(Table1[Grade])),FILTER(Table1[Grade],ISNUMBER(Table1[Grade])),ARRAYTOTEXT,0,0)
And my proposition of modification of Peter's formula:
Excel Formula:
=GROUPBY(CHOOSECOLS(FILTER(Table1,ISNUMBER(Table1[Grade])),1,6),FILTER(Table1[Grade],ISNUMBER(Table1[Grade])),ARRAYTOTEXT,0,0)
again: no headers automatically added to final formula output, but I don't think it is an issue - headers are a constant part
 
Upvote 0
Though if you did want to include the headers (with the same assumptions* as post 4) ..
* If those assumptions are incorrect then modifications would most likely still be possible.

Hart.xlsm
ABCGNOPQR
1Last NameFirst NameParentsGradeLast NameParentsGrade
2AndersonPeterMaria, John3AndersonMaria, John3, 4
3AndersonAnneMaria, John3xScottMaria, Jack5
4AndersonIanMaria, John4ScottMaria, John6
5BrownKevinAnna, Peter3A
6ScottLilyMaria, JackB4
7ScottPeterMaria, Jack5
8ScottPeterMaria, John6
9
10
Sheet1
Cell Formulas
RangeFormula
P1:R4P1=LET(g,Table1[[#All],[Grade]],f,CHOOSECOLS(FILTER(Table1[#All],ISNUMBER(g)+(g="grade")),1,6,13),GROUPBY(TAKE(f,,2),TAKE(f,,-1),ARRAYTOTEXT,3,0))
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,224,748
Messages
6,180,721
Members
452,995
Latest member
isldboy

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