Readjust four column values by ignoring blank cells (Google Sheets)

前端 未结 1 951
北荒
北荒 2021-01-28 13:55

I have this values:

And I would like the formula to ignore blank cells, with the final result in the following sequence:

I tried t

相关标签:
1条回答
  • 2021-01-28 14:40

    How about this modified formula?

    Modified formula:

    =ARRAYFORMULA(TRIM(SPLIT(TRANSPOSE(SPLIT(REGEXREPLACE(TEXTJOIN(",",TRUE,A1:D),"(([\w\s]+,){3}[\w\s]+)","$1@"),"@")),",")))
    
    • The flow of this formula is as follows.
      1. Join all cell values by ignoring the empty cells using TEXTJOIN.
      2. Put @ to the joined text value for 4 columns using REGEXREPLACE.
      3. Split the text value with @ using SPLIT.
      4. Transpose the splitted values using TRANSPOSE.
      5. Split the each row with , using SPLIT.

    Result:

    Note:

    • If , and @ are included in the cell values, please change them in the formula.

    References:

    • TEXTJOIN
    • REGEXREPLACE
    • SPLIT
    • TRANSPOSE

    Added 1:

    About I guess this will fail, if cell values are more than 1 character. of TheMaster's comment, I tested it as follows.

    Added 2:

    For OP's new situation, I added the below modified formula. In this case, the regex is modified.

    Modified formula:

    =ARRAYFORMULA(TRIM(SPLIT(TRANSPOSE(SPLIT(REGEXREPLACE(TEXTJOIN(",",TRUE,A1:D),"(([\w\s\S]+?,){4})","$1@"),"@")),",")))
    

    Result:

    0 讨论(0)
提交回复
热议问题