I am trying to determine the font alignment in each cell in a range based on the cell’s value. Each cell contains a start time and end time (ie. 9:30am-5:30pm) in which I am trying to set the alignment based on the start time:
- Shifts starting between 4:00am and 10:59am : Left Align——–(>4am <11am)
- Shifts starting between 11:00am and 2:00pm : Center Align—–(>=11am <=2pm)
- Shifts starting between 2:01pm and 3:59am : Right Align——–(>2pm <4am)
- Everything else Center Align
Looks like this:
I have read numerous posts that accomplish portions of what I am trying to do but I haven’t been able to create a solution that works, my script so far is probably worth ignoring. Here is an Example Sheet.
As for the script…
function Test1() {
const wb = SpreadsheetApp.getActiveSpreadsheet();
const sheet = wb.getActiveSheet();
const values = sheet.getRange(1,1,26,8).getValues();
then I tried to unsuccessfully use the following approaches however I could not figure out how to search by part of a string or to splice all the values in a range or splice and handle value as Timevalue. Here are the other posts I tried to incorporate:
Align all numbers in range – could not figure out how to search part of string.
Text contains valueCould not figure out the proper way to set the formatting in the “do something section”
Based on value Could only get it to work with full string and only in the first column.