How to Make Class Rosters from Google Sheets: One PDF per Class, Sorted by Last Name, with Seat Counts and an Attendance Grid (2026)

Most schools, tutoring centers, after-school programs and coaches end up with the same spreadsheet: one long list of who is in which class. What each teacher actually needs is their own list, sorted by last name, with the right count and room to take attendance, and making those by filtering, copying and printing one class at a time is where an evening goes. This guide keeps the enrollment list as the one place you edit, adds counts and checks with formulas, shows any class on screen with a dropdown, and uses a free Apps Script to save one roster PDF per class in a Drive folder, with students A–Z, preferred names, enrolled against capacity, a waitlist and blank attendance columns.

For one list of everyone at a single event (a sign-in sheet and seating lists), the event sign-in sheet guide fits better. For a report or certificate per student, see student progress reports and training completion certificates.

Step 1: an Enrollments tab with one row per student per class

Name a tab Enrollments and type these headers in row 1. A student in four classes has four rows, so changing a schedule means editing one row, not rebuilding a list. H and I are formulas.

ColHeaderWhat goes in it
AStudent IDWhatever ID your school uses. It is how the checks tell two students with the same name apart. Use Format › Number › Plain text if IDs have leading zeros.
B, CLast name, First nameIn separate columns, so the roster can sort by last name
DGoes byA preferred name, if the student uses one. It is shown in brackets after the legal name.
EGradeGrade or year level (or leave it empty)
FClassThe class code exactly as on the Classes tab. A Data › Data validation › Dropdown (from a range) with Classes!A2:A stops typos.
GStatusA Data › Data validation dropdown with Enrolled, Waitlist and Dropped
H, IRoster name, CheckFormulas, below

Roster name (H2, filled down) is “Last, First”, with the preferred name in brackets:

=IF(B2="", C2, B2&IF(C2="", "", ", "&C2))&IF(D2="", "", " ("&D2&")")

Check (I2) is empty when the row is fine. Otherwise it says No ID, Unknown class (the class isn’t on the Classes tab yet), or Listed twice (the same Student ID twice in one class, not counting Dropped rows). It uses COUNTIF and COUNTIFS:

=IF(F2="", "", IF(A2="", "No ID", IF(COUNTIF(Classes!$A$2:$A, F2)=0, "Unknown class", IF(AND(G2<>"Dropped", COUNTIFS($A$2:$A, A2, $F$2:$F, F2, $G$2:$G, "<>Dropped")>1), "Listed twice", ""))))
A
Student ID
B
Last name
C
First name
D
Goes by
E
Grade
F
Class
G
Status
H
Roster name
I
Check
1001AlvarezSofia9ALG1-P2EnrolledAlvarez, Sofia
1002NguyenThanhTim9ALG1-P2EnrolledNguyen, Thanh (Tim)
1003LeeJordan9ALG1-P2EnrolledLee, Jordan
1004LeedsAva9ALG1-P2EnrolledLeeds, Ava
1005OkoroDanielDanny9ALG1-P2EnrolledOkoro, Daniel (Danny)
1006ParkHana9ALG1-P2WaitlistPark, Hana
1001AlvarezSofia9BIO-P3EnrolledAlvarez, Sofia
1003LeeJordan9BIO-P3EnrolledLee, Jordan
1006ParkHana9BIO-P3EnrolledPark, Hana
1007SchmidtLukas10BIO-P3EnrolledSchmidt, Lukas
1008HaddadMira10BIO-P3EnrolledHaddad, Mira
1010ReyesCarmen10BIO-P3WaitlistReyes, Carmen
1002NguyenThanhTim9ART-P5EnrolledNguyen, Thanh (Tim)
1007SchmidtLukas10ART-P5DroppedSchmidt, Lukas
1008HaddadMira10ART-P5EnrolledHaddad, Mira
1004LeedsAva9HIST-P1EnrolledLeeds, Ava
1005OkoroDanielDanny9HIST-P1EnrolledOkoro, Daniel (Danny)Listed twice
1005OkoroDanielDanny9HIST-P1EnrolledOkoro, Daniel (Danny)Listed twice
1009ItoKen10GEO-P4EnrolledIto, KenUnknown class

Example data: the students, teachers and classes are made up.

Step 2: a Classes tab with counts and seats left

Make a second tab named Classes, one row per class (one roster each). A to G are typed, H to J are formulas, and K and L are filled in by the script.

ColHeaderWhat goes in it
AClassA short unique code per section, such as ALG1-P2 for Algebra 1 in period 2
B to FCourse, Teacher, Teacher email, Period, RoomPrinted at the top of the roster. Teacher email is only needed if the script emails the rosters.
GCapacitySeats in the room or the section limit (or leave it empty)
H, I, JEnrolled, Seats left, WaitlistFormulas, below
K, LRoster PDF, Made atLeft empty for the script

Put these in H2, I2 and J2 and fill them down:

=IF(A2="", "", COUNTIFS(Enrollments!$F$2:$F, A2, Enrollments!$G$2:$G, "Enrolled"))
=IF(OR(A2="", G2=""), "", G2-H2)
=IF(A2="", "", COUNTIFS(Enrollments!$F$2:$F, A2, Enrollments!$G$2:$G, "Waitlist"))
A
Class
B
Course
C
Teacher
D
Teacher email
E
Period
F
Room
G
Capacity
H
Enrolled
I
Seats left
J
Waitlist
ALG1-P2Algebra 1Ms. Riverarivera@example.edu21145501
BIO-P3BiologyMr. Chenchen@example.edu3L245-11
ART-P5Studio ArtMs. Okaforokafor@example.edu5A13210
HIST-P1World HistoryMr. Brooksbrooks@example.edu12076330

The Classes tab for the example. Roster PDF and Made at (K, L) are left out.

Algebra 1 is exactly full with one student waiting. Biology has 5 students in 4 seats, so Seats left is -1. World History shows 3 enrolled, but Daniel is on two rows (both are flagged Listed twice), so it really has 2: delete the extra row and the count corrects itself. Ken is enrolled in GEO-P4, which isn’t on the Classes tab yet, so he would be on nobody’s roster; that is what Unknown class is for.

Then add four Format › Conditional formatting rules with Custom formula is: select A2:L on the Classes tab for the first two, and A2:I on the Enrollments tab for the other two.

TabCustom formulaColorMeaning
Classes=AND(ISNUMBER($I2), $I2<0)RedMore students enrolled than seats
Classes=AND(ISNUMBER($I2), $I2=0)AmberFull
Enrollments=$I2<>""OrangeThe row needs fixing
Enrollments=$G2="Dropped"Grey textDropped, kept for the record

Step 3: one class on screen

For a quick look (or a one-off printout of a single class), make a tab named Roster. Put a Data › Data validation › Dropdown (from a range) with Classes!A2:A in B1, type Student, ID and Grade in A2:C2, and put this in A3. It uses FILTER to keep the enrolled students of the chosen class and SORT to order them. Google’s SORT page says a sort column can be “a range outside of range”, which is what lets it sort by the Last name column and then the First name column while showing the “Last, First” column:

=IFERROR(SORT(FILTER({Enrollments!H2:H, Enrollments!A2:A, Enrollments!E2:E}, Enrollments!F2:F=B1, Enrollments!G2:G="Enrolled"), FILTER(Enrollments!B2:B, Enrollments!F2:F=B1, Enrollments!G2:G="Enrolled"), TRUE, FILTER(Enrollments!C2:C, Enrollments!F2:F=B1, Enrollments!G2:G="Enrolled"), TRUE), "No students enrolled")

With ALG1-P2 chosen in B1:

A
Student
B
ID
C
Grade
Alvarez, Sofia10019
Lee, Jordan10039
Leeds, Ava10049
Nguyen, Thanh (Tim)10029
Okoro, Daniel (Danny)10059

The Roster tab for ALG1-P2. If FILTER finds nobody it returns #N/A, which IFERROR turns into “No students enrolled”.

Lee comes before Leeds, and Nguyen sorts by his legal last name even though he goes by Tim. Hana is on the waitlist, so she isn’t on the list.

Step 4: one roster PDF per class

Open Extensions › Apps Script, paste the script below, set FOLDER_ID (the last part of the Drive folder’s URL), SCHOOL and TERM, and save. Then:

  1. Reload the spreadsheet. A Rosters menu appears (it is created by the script’s onOpen, as described in Google’s custom menus page).
  2. Choose Rosters › Make rosters for all classes and approve the permissions. PREVIEW is true, so it makes two PDFs named PREVIEW and writes nothing to the sheet.
  3. Open the previews. When they look right, set PREVIEW = false, save, and run it again.
/**
 * Class rosters from Google Sheets: one PDF per class, students A-Z by last name, with an attendance grid.
 *
 * Tab "Enrollments" (row 1 = headers, extra columns are fine), one row per student per class:
 *   Student ID | Last name | First name | Goes by | Grade | Class | Status (Enrolled, Waitlist or Dropped)
 * Tab "Classes", one row per class (one PDF each):
 *   Class | Course | Teacher | Teacher email | Period | Room | Capacity | ... | Roster PDF | Made at
 *
 * Each run makes a fresh PDF for every class (or only the class rows you have selected) in your
 * Drive folder and writes its link and the time back to the class row. Run it with PREVIEW = true
 * first: it makes up to 2 PDFs named "PREVIEW", writes nothing to the sheet, and emails (if
 * EMAIL_TEACHERS is on) go only to you.
 */
const FOLDER_ID          = 'PASTE_OUTPUT_FOLDER_ID';
const SCHOOL             = 'Your School';
const TERM               = 'Spring 2027';
const ATTENDANCE_COLUMNS = 5;      // blank columns for dates or ticks (0 = none)
const SHOW_WAITLIST      = true;   // list waitlisted students under the table
const EMAIL_TEACHERS     = false;  // true emails each PDF to the class's Teacher email
const PREVIEW            = true;   // set to false for the real run
const KEEP_DOCS          = false;  // true keeps the Google Doc next to each PDF
const MAX_PER_RUN        = 40;

function onOpen() {
  SpreadsheetApp.getUi().createMenu('Rosters')
    .addItem('Make rosters for all classes', 'makeAllRosters')
    .addItem('Make rosters for selected class rows', 'makeSelectedRosters')
    .addToUi();
}

function makeAllRosters(now) {
  return makeRosters_(null, now);
}

function makeSelectedRosters(now) {
  const sh = SpreadsheetApp.getActive().getActiveSheet();
  if (sh.getName() !== 'Classes') {
    SpreadsheetApp.getUi().alert('Select one or more rows on the Classes tab first.');
    return null;
  }
  const range = sh.getActiveRange();
  const rows = {};
  for (let r = range.getRow(); r < range.getRow() + range.getNumRows(); r++) rows[r] = true;
  return makeRosters_(rows, now);
}

function makeRosters_(onlyRows, now) {
  now = now instanceof Date ? now : new Date();
  const lock = LockService.getDocumentLock();
  if (!lock.tryLock(30000)) return { busy: true };       // another run is busy; try again in a minute
  try {
    const started = Date.now();
    const ss = SpreadsheetApp.getActive();
    const tz = ss.getSpreadsheetTimeZone();
    const cs = ss.getSheetByName('Classes'), es = ss.getSheetByName('Enrollments');
    if (!cs || !es) throw new Error('This needs a "Classes" tab and an "Enrollments" tab.');
    const cv = cs.getDataRange().getDisplayValues();    // print values exactly as the sheet shows them
    const ev = es.getDataRange().getDisplayValues();
    const c = columns_(cv[0], ['Class', 'Course', 'Teacher', 'Teacher email', 'Period', 'Room', 'Capacity', 'Roster PDF', 'Made at'], 'Classes');
    const e = columns_(ev[0], ['Student ID', 'Last name', 'First name', 'Goes by', 'Grade', 'Class', 'Status'], 'Enrollments');
    const problems = [];

    const classes = {};
    for (let r = 1; r < cv.length; r++) {
      const key = cv[r][c['Class']].trim().toLowerCase();
      if (key) classes[key] = { enrolled: [], waitlist: [], seen: {} };
    }
    for (let r = 1; r < ev.length; r++) {
      const v = ev[r].map((x) => String(x).trim());
      const last = v[e['Last name']], first = v[e['First name']], cls = v[e['Class']];
      if (!last && !first && !cls) continue;                               // empty row
      const where = 'Enrollments row ' + (r + 1);
      if (!last && !first) { problems.push(where + ': no name'); continue; }
      const status = v[e['Status']].toLowerCase();
      if (!cls) { problems.push(where + ': no Class'); continue; }
      const k = classes[cls.toLowerCase()];
      if (!k) { problems.push(where + ': class ' + cls + ' is not on the Classes tab'); continue; }
      if (['enrolled', 'waitlist', 'dropped'].indexOf(status) < 0) { problems.push(where + ': Status must be Enrolled, Waitlist or Dropped'); continue; }
      if (status === 'dropped') continue;
      const id = v[e['Student ID']];
      if (!id) problems.push(where + ': no Student ID (listed anyway)');
      else if (k.seen[id.toLowerCase()]) { problems.push(where + ': student ' + id + ' is already in ' + cls + ' on row ' + k.seen[id.toLowerCase()] + ' (left out)'); continue; }
      else k.seen[id.toLowerCase()] = r + 1;
      const goes = v[e['Goes by']];
      const s = { row: r + 1, id: id, last: last, first: first, grade: v[e['Grade']],
        name: (last && first ? last + ', ' + first : last || first) + (goes ? ' (' + goes + ')' : '') };
      (status === 'enrolled' ? k.enrolled : k.waitlist).push(s);
    }

    const folder = DriveApp.getFolderById(FOLDER_ID);
    const me = Session.getEffectiveUser().getEmail();
    const stamp = Utilities.formatDate(now, tz, 'yyyy-MM-dd');
    const printed = Utilities.formatDate(now, tz, 'MMMM d, yyyy');
    const over = [], noEmail = [];
    let made = 0, emailed = 0, stopped = '';

    for (let r = 1; r < cv.length; r++) {
      if (onlyRows && !onlyRows[r + 1]) continue;
      const row = cv[r].map((x) => String(x).trim());
      const code = row[c['Class']];
      if (!code) continue;
      if (made >= (PREVIEW ? 2 : MAX_PER_RUN)) { stopped = 'limit'; break; }
      if (Date.now() - started > 270000) { stopped = 'time'; break; }      // stay inside the 6-minute limit
      const addr = row[c['Teacher email']];
      const canEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(addr);
      if (EMAIL_TEACHERS && canEmail && MailApp.getRemainingDailyQuota() < 1) { stopped = 'quota'; break; }
      const k = classes[code.toLowerCase()];
      const list = k.enrolled.slice().sort(byName_);
      const course = row[c['Course']];
      const capText = row[c['Capacity']];
      const cap = capText === '' ? NaN : Number(capText);
      if (!isNaN(cap) && list.length > cap) over.push(code + ' (' + list.length + ' of ' + cap + ')');

      const name = (PREVIEW ? 'PREVIEW ' : '') + [TERM, code, course, 'roster', stamp].filter(String).join(' ');
      const doc = DocumentApp.create(name);
      const file = DriveApp.getFileById(doc.getId());
      file.moveTo(folder);
      const body = doc.getBody();
      body.setMarginTop(36).setMarginBottom(36).setMarginLeft(36).setMarginRight(36);
      const title = body.getParagraphs()[0];                               // a new Doc starts with one empty paragraph
      title.setText(course ? course + ' (' + code + ')' : code);
      title.setHeading(DocumentApp.ParagraphHeading.HEADING2);
      const info = [SCHOOL, TERM, row[c['Teacher']],
        row[c['Period']] ? 'Period ' + row[c['Period']] : '', row[c['Room']] ? 'Room ' + row[c['Room']] : ''];
      body.appendParagraph(info.filter(String).join(' \u00b7 ')).setHeading(DocumentApp.ParagraphHeading.NORMAL);
      const count = list.length + ' enrolled' + (isNaN(cap) ? '' : ' of ' + cap + ' seats' +
        (list.length > cap ? ' (over by ' + (list.length - cap) + ')' : '')) + ' \u00b7 Printed ' + printed;
      body.appendParagraph(count).setHeading(DocumentApp.ParagraphHeading.NORMAL);
      if (list.length) {
        const blanks = [];
        for (let i = 0; i < ATTENDANCE_COLUMNS; i++) blanks.push('');
        const cells = [['#', 'Student', 'ID', 'Grade'].concat(blanks)].concat(
          list.map((s, i) => [String(i + 1), s.name, s.id, s.grade].concat(blanks)));
        const table = body.appendTable(cells);
        table.getRow(0).editAsText().setBold(true);
        for (let i = 1; i < table.getNumRows(); i++) table.getRow(i).setMinimumHeight(20);
        const width = (body.getPageWidth() || 612) - 72;                  // 612 pt = US Letter
        const fixed = [24, 170, 60, 45];
        fixed.forEach((w, i) => table.setColumnWidth(i, w));
        const rest = Math.max(30, Math.floor((width - 299) / Math.max(1, ATTENDANCE_COLUMNS)));
        for (let i = 0; i < ATTENDANCE_COLUMNS; i++) table.setColumnWidth(4 + i, rest);
      } else {
        body.appendParagraph('No students enrolled yet.');
      }
      if (SHOW_WAITLIST && k.waitlist.length) {
        body.appendParagraph('Waitlist, in sign-up order: ' + k.waitlist.map((s) => s.name).join('; '));
      }
      doc.saveAndClose();
      const pdf = folder.createFile(file.getAs(MimeType.PDF)).setName(name + '.pdf');
      if (!KEEP_DOCS) file.setTrashed(true);
      if (!PREVIEW) {
        cs.getRange(r + 1, c['Roster PDF'] + 1).setValue(pdf.getUrl());
        cs.getRange(r + 1, c['Made at'] + 1).setValue(now);
      }
      made++;

      if (EMAIL_TEACHERS) {
        if (!canEmail) { noEmail.push(code); continue; }
        MailApp.sendEmail({
          to: PREVIEW ? me : addr,
          subject: (PREVIEW ? '[PREVIEW to ' + addr + '] ' : '') + 'Class roster: ' + (course || code) + ' (' + code + '), ' + TERM,
          body: 'Hi ' + (row[c['Teacher']] || '') + ',\n\nThe roster for ' + (course || code) + ' is attached: ' + count + '.' +
                (k.waitlist.length ? ' Waitlist: ' + k.waitlist.length + '.' : '') + '\n\n' + SCHOOL,
          name: SCHOOL,
          attachments: [pdf.getAs(MimeType.PDF)]
        });
        emailed++;
      }
    }
    const note = 'Made ' + made + ' roster(s)' + (PREVIEW ? ' in PREVIEW (nothing written to the sheet)' : '') +
      (EMAIL_TEACHERS ? ', emailed ' + emailed : '') + '.' +
      (over.length ? ' Over capacity: ' + over.join(', ') + '.' : '') +
      (problems.length ? ' ' + problems.length + ' enrollment problem(s), see the log.' : '') +
      (noEmail.length ? ' No valid Teacher email for ' + noEmail.join(', ') + '.' : '') +
      (stopped ? ' Stopped early (' + stopped + '); run it again for the rest.' : '');
    problems.forEach((p) => console.log(p));
    ss.toast(note, 'Rosters', 10);
    return { made: made, emailed: emailed, over: over, problems: problems, noEmail: noEmail, stopped: stopped };
  } finally {
    lock.releaseLock();
  }
}

/** Finds each needed header (ignoring case and spaces) or stops with a clear message. */
function columns_(header, need, tab) {
  const head = header.map((h) => String(h).trim().toLowerCase());
  const missing = need.filter((n) => head.indexOf(n.toLowerCase()) < 0);
  if (missing.length) throw new Error('Missing column(s) on ' + tab + ': ' + missing.join(', '));
  const c = {};
  need.forEach((n) => { c[n] = head.indexOf(n.toLowerCase()); });
  return c;
}

/** Last name, then first name, ignoring case and accents; ties keep sheet order. */
function byName_(a, b) {
  const cmp = (x, y) => String(x).localeCompare(String(y), undefined, { sensitivity: 'base', numeric: true });
  return cmp(a.last || a.first, b.last || b.first) || cmp(a.last ? a.first : '', b.last ? b.first : '') || a.row - b.row;
}

For the example, the Algebra 1 roster comes out like this (the five unlabeled columns are the attendance grid):

Algebra 1 (ALG1-P2)
Your School · Spring 2027 · Ms. Rivera · Period 2 · Room 114
5 enrolled of 5 seats · Printed November 23, 2026

#StudentIDGrade
1Alvarez, Sofia10019
2Lee, Jordan10039
3Leeds, Ava10049
4Nguyen, Thanh (Tim)10029
5Okoro, Daniel (Danny)10059

Waitlist, in sign-up order: Park, Hana

What the script does

Keeping rosters current

Pitfalls

FAQ

How do I make a class roster in Google Sheets?

Keep one Enrollments tab with a row per student per class (Student ID, Last name, First name, Goes by, Grade, Class, Status) and a Classes tab with a row per class. For an on-screen roster, pick a class in a dropdown and list its enrolled students A–Z with SORT and FILTER. For printable rosters, the Apps Script on this page saves one PDF per class with the students in a numbered table.

How do I sort a class list by last name in Google Sheets?

Keep last and first names in separate columns and sort by both. SORT accepts a sort column that is a range outside the data, so =SORT(FILTER(names, conditions), FILTER(last names, conditions), TRUE, FILTER(first names, conditions), TRUE) sorts by last name and then first name while showing a “Last, First” column. Sorting a single “First Last” column sorts by first name instead.

How do I print a separate roster for each class from one sheet?

Google Sheets can print or download a sheet as one PDF, but it has no option to make a separate file for each group of rows. The script on this page groups the Enrollments rows by class and makes a Google Doc and PDF for each row of the Classes tab, with the teacher, period, room, the enrolled count against capacity, a numbered student table and blank attendance columns, and writes each PDF’s link back to the class row.

How do I count students per class and see which classes are full?

On the Classes tab, Enrolled is =IF(A2="", "", COUNTIFS(Enrollments!$F$2:$F, A2, Enrollments!$G$2:$G, "Enrolled")) and Seats left is the capacity minus that. A conditional-formatting rule colors a class amber when Seats left is 0 and red when it is negative, so over-enrolled sections stand out.

How do I handle students who drop a class or are on a waitlist?

Don’t delete the row: set Status to Dropped (it stays in the history and stops counting) or Waitlist. Waitlisted students are counted separately, left out of the student table and listed under it in sign-up order, so the teacher can see who is next. When a seat opens, change the student’s Status to Enrolled and make that roster again.

Can I email each teacher their class roster?

Yes. Set EMAIL_TEACHERS = true in the script and each roster PDF is emailed to the class’s Teacher email. Run it with PREVIEW = true first: it makes two PDFs named PREVIEW, writes nothing to the sheet, and sends the emails only to you. Apps Script’s daily email quota is 100 recipients on a consumer Gmail account and 1,500 on Google Workspace.

Need a document for each student or each class? SheetWeave (disclosure: we make it) is a Google Sheets add-on that fills a Google Docs template with each row's column values and saves a Doc, a PDF, or both in a Drive folder you choose, writing the links back to the row. From the Enrollments tab that means a placement or welcome letter per student row; from the Classes tab, a one-page class sheet per class with the teacher, period, room, Enrolled and Seats left columns. It can run on selected rows, all rows, or only new ones. For the student table in each roster, use the script above. Sheet data stays inside your Google account. 14-day free trial, no credit card required. SheetWeave is on the Google Workspace Marketplace.
See SheetWeave

Related Google Sheets guides

Instructions refer to Google Sheets and Apps Script as they worked on November 23, 2026. Not affiliated with Google. Google Sheets and Google Docs are trademarks of Google LLC. Questions or corrections: hello@loomwise.app.