I am working on a program calendar for work, and need to bold alternating programs within the same cell. I have never used apps script before successfully, and am unsure of how to make it work.
calender format
Each cell with program names uses this formula to pull data from another sheet:
=JOIN(", ", IFERROR(QUERY(FILTER(Dates!$A$2:$A & " (" & Dates!$C$2:$C & ")",
(Dates!$D$2:$D = INDIRECT(ADDRESS(ROW()-1, COLUMN()))) +
(Dates!$E$2:$E = INDIRECT(ADDRESS(ROW()-1, COLUMN()))) +
(Dates!$F$2:$F = INDIRECT(ADDRESS(ROW()-1, COLUMN()))) +
(Dates!$G$2:$G = INDIRECT(ADDRESS(ROW()-1, COLUMN()))) +
(Dates!$H$2:$H = INDIRECT(ADDRESS(ROW()-1, COLUMN()))) +
(Dates!$I$2:$I = INDIRECT(ADDRESS(ROW()-1, COLUMN()))) +
(Dates!$J$2:$J = INDIRECT(ADDRESS(ROW()-1, COLUMN()))) +
(Dates!$K$2:$K = INDIRECT(ADDRESS(ROW()-1, COLUMN()))) +
(Dates!$L$2:$L = INDIRECT(ADDRESS(ROW()-1, COLUMN()))) +
(Dates!$M$2:$M = INDIRECT(ADDRESS(ROW()-1, COLUMN()))) +
(Dates!$N$2:$N = INDIRECT(ADDRESS(ROW()-1, COLUMN())))),
"select Col1"), ""))
This gives an output of: Athletic U (4), Vex Iq (24), Master Builders (24), FYST (24). This is All given within one cell.
I would like to auto bold every other output so it would read: Athletic U (4), Vex Iq (24), Master Builders (24), FYST (24).
Is there a way to do this with apps script?
I tried to use chat GPT to write the apps script since I can’t, but (shockingly) it didn’t work.
T1
function alternateBoldText() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var range = sheet.getActiveRange();
var values = range.getValue().split(',');
var formattedValues = [];
for (var i = 0; i < values.length; i++) {
if (i % 2 == 0) {
formattedValues.push(values[i]);
} else {
formattedValues.push(values[i].bold());
}
}
var formattedString = formattedValues.join(', ');
range.setValue(formattedString);
}
T2
=ISEVEN(ROUNDUP((LEN(A1)-LEN(SUBSTITUTE(A1, ",", "")))/2,0))
T3
function alternateBoldTextInRange(range) {
var output = [];
range.forEach(function(row) {
var bold = false;
var cellValue = row[0];
var segments = cellValue.split(',');
var formattedSegments = [];
for (var i = 0; i < segments.length; i++) {
if (segments[i].trim() !== "") {
formattedSegments.push(bold ? "<b>" + segments[i].trim() + "</b>" : segments[i].trim());
bold = !bold;
}
}
output.push([formattedSegments.join(', ')]);
});
return output;
}
was the best one to date, but it would return “Vex Go Racing (3), Lego Explorer (3)“
Hayden Reynolds is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.