Search code examples
google-apps-scriptgoogle-sheetsgoogle-sheets-formula

how to automatically add a single blank row, after similar date entries in google sheets?


I am making an expense tracker. Suppose in this, I have purchased 5 things on 1 Aug 2021, 3 things on 2 Aug 2021, 4 things on 3 Aug 2021, and so forth. I am pushing the data through google forms and I want that upon entering the data for a particular date, google sheets must automatically analyze whether the entry is of the same date or different. If it is of a different date, then a blank row must be added between the two distinctive dates.

Mainly, I want to group the same date entries and all in all, make different date entries blocks just to keep the table neat.

I couldn't think of any way apart from manually entering a blank row. I am new to google sheets. Thanks in advance.

enter image description here

enter image description here


Solution

  • Alternatively, if you don't want to modify your source data (which is more advised), you can use a formula for that:

    =ArrayFormula(iferror(
    split(transpose(split(textjoin(",",true,
       if(len(A2:A),
           {A2:B,if(A2:A<>A3:A,";;",";")
            },
    )),";",true,false)),",",true,true)))
    

    enter image description here