google-sheetsgoogle-sheets-formula

How can I keep background colours active when text are added to cells


I'm making a Google Sheet for instructors that they can use to reserve spaces. I had someone help me make a formula that colour the background depending on how much time they want to reserve a space. If "Tom" wanted to reserve 60min lesson, He would add 60 after his name and the formula will add background colour to 3 cells below.

Here is the fomular that does it.

=index(let(Σ,xlookup("?*",to_text(C$5:C5),C$5:C5,,2,-1),xmatch(cell("address",C5),address(row(Σ)+sequence(choosecols(split(Σ," "),-1)/15,1,0),column(Σ)))))

I would like to be able to add student's name in one of those coloured cells. If I add a name right now, all the coloured cell disappears. I used "Richard" as an example in this photo. enter image description here

I would like to look like this in this photo. enter image description here

Thank you.


Solution

  • Change this part of the existing formula

    xlookup("?*",to_text(B$2:B2),B$2:B2,,2,-1)
    

    to

    xlookup(1,--regexmatch(B$2:B2," \d+$"),B$2:B2,,,-1)
    

    Full formula:

    =index(let(Σ,xlookup(1,--regexmatch(B$2:B2," \d+$"),B$2:B2,,,-1),xmatch(cell("address",B2),address(row(Σ)+sequence(choosecols(split(Σ," "),-1)/15,1,0),column(Σ)))))
    

    enter image description here