Run your first custom function in a Sheet
The registration desk gets a booth code like West-007. Split it into a hall and a badge number while keeping all three digits.
Install the function in your spreadsheet
Open a blank Google Sheet. Choose Extensions → Apps Script. In the editor, add a script file called Booth, paste the code below and click Save. Return to the spreadsheet tab.
Booth.gs
Apps Script
/**
* Splits a hall and its numeric booth ID into two columns.
*
* @param {string|string[][]} codes One code or a single-column range.
* @return {string[][]} Hall and booth ID, one row per source cell.
* @customfunction
*/
function BOOTHCODE(codes) {
const rows = Array.isArray(codes) ? codes : [[codes]];
return rows.map(function (row) {
if (row.length !== 1) throw new Error('Select one column of booth codes.');
const text = String(row[0]).trim();
if (!text) return ['', ''];
const match = /^(.+)-(\d+)$/.exec(text);
return match ? [match[1], match[2]] : ['Check code', ''];
});
}
Try a blocked result
- Enter
West-007in A2. Leave A3 empty. EnterNeeds reviewin A4 andEast-12in A5. - Type
Keep aisle clearin C2. In B2 enter=BOOTHCODE(A2:A5). B2 shows#REF!because the second output column would overwrite C2. Your note stays in place. - Clear the formula in B2. Enter the same formula in E2 with E2:F5 empty. The first row shows
Westand007. The blank stays blank, the malformed code showsCheck code, and the last row showsEastand12. - Change A2 to
West-009. F2 now reads009because the formula references the source range.
For your own function, use its name and arguments in the cell formula. Google’s custom function guide