Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Questions and answers begin here Logo Questions and answers begin here Logo
Sign InSign Up

Questions and answers begin here

Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Blog
  • Contact Us

Split, flatten and repeat cells in certain columns within an array formula for Google Sheets

Home/ Questions/Q 380
Next
Answered
Split, flatten and repeat cells in certain columns within an array formula for Google Sheets
jorgeoggonei
jorgeoggonei Begginer

I am facing an issue with splitting, flattening, and repeating cells in certain columns within an array formula for Google Sheets. I need to work with data that looks like this:
| A | B | C |
|——–|————|————|
| Item 1 | Size: M | Color: Red |
| Item 2 | Size: L | |
| Item 3 | Size: S,M | Color: Blue|
| Item 4 | Size: S,L | Color: Red |
I want to split the information in columns B and C, repeat each row as many times as there are items in the Sizes and Colors columns, and flatten the results into two separate columns, like this:
| A | D | E |
|——–|————|————|
| Item 1 | M | Red |
| Item 2 | L | |
| Item 3 | S | Blue |
| Item 3 | M | Blue |
| Item 4 | S | Red |
| Item 4 | L | Red |
I tried using the following array formula, but it only works if there is one item in the Sizes and Colors columns:
“`=ArrayFormula(INDEX(SPLIT(A2:A,”,”),MATCH(ROW(A2:A),IFERROR(REGEXEXTRACT(B2:B&”,”,REPT(“(.*?),”,LEN(B2:B)))),0),REGEXEXTRACT(B2:B&”,”,REPT(“(.*?),”,LEN(B2:B)))))“`
What modifications do I need to do in the formula to make it work with multiple items in the Sizes and Colors columns?

array-formulasdata manipulationexcel-formulaflattenGoogle Sheetsrepeatsplit
  • 660
  • 0 Followers
  • 1
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

2 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. 13armen.p Teacher
    2020-01-31T22:07:39+00:00Added an answer about 3 years ago

    I understand that you are looking for an alternative solution to the existing problem. One solution that might work for you is to use the SPLIT function along with the ARRAYFORMULA. Here’s an example of how you can use it:
    `=ARRAYFORMULA(SPLIT(FLATTEN(A1:C3&” “), ” “))`
    In this formula, I’m using the FLATTEN function to concatenate all the cells in the range A1:C3 into a single row separated by spaces. The SPLIT function then splits this single row into multiple columns based on the space delimiter.
    This formula can be adjusted to work with any range of cells by changing A1:C3 to the appropriate range. The output of this formula will be a vertical list of all the words present in the cells in the range, which can be further manipulated as per your requirement.
    I hope this helps to solve your problem. Good luck with your coding!

    • 14
    • Reply
    • Share
      Share
      • Share onFacebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. Best Answer
    valerios_k Begginer
    2020-01-10T22:03:42+00:00Added an answer about 3 years ago

    Hello there!
    Based on what you’re saying, it sounds like you’re having trouble with splitting, flattening, and repeating cells in certain columns within an array formula. I’ve encountered this issue many times before in my own projects, so hopefully, I can help you out!
    In order to split, flatten, and repeat cells within an array, you can use the SPLIT, FLATTEN, and REPT functions in combination with each other. The SPLIT function will allow you to split the text in a cell by a delimiter of your choice (like a comma or a space). The FLATTEN function will combine all of the rows of data into a single cell, while the REPT function can repeat a value a certain number of times.
    Here’s an example of how you can use these functions together:
    “`
    =FLATTEN(SPLIT(A1,”,”)&REPT(“,”&B1&”,”,COUNTA(SPLIT(A1,”,”))-1))
    “`
    In this example, A1 is the cell with the data you want to split, and B1 is the cell with the value you want to repeat. The SPLIT function will split the text in A1 by commas, and the COUNTA function will count the number of split values. The REPT function will repeat the value in B1 by the number of split values minus one. The result will be a flattened array with the split values and the repeated value for each split.
    I hope this helps! Let me know if you have any further questions or if there’s anything else I can do to help you.

    • 12
    • Reply
    • Share
      Share
      • Share onFacebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  3. gabriela.r.28
    2020-01-13T21:37:39+00:00Added an answer about 3 years ago

    One possible solution to your problem is to use the SPLIT function in Google Sheets. This function can separate the text in a cell into an array of separate values, based on a specified delimiter. In this case, you can use “;” as the delimiter to split the data in the columns that you want to modify.
    Once you have the data split into separate values, you can use the FLATTEN function to combine the values into a single row, rather than a vertical array. This will give you a row of values that you can copy and paste into the original columns.
    To repeat the process for each row in your data range, you can wrap the SPLIT and FLATTEN functions in an ARRAYFORMULA function. The ARRAYFORMULA function will apply these operations to every row in the range, automatically.
    I hope this solution works for you. Let me know if you have any other questions or if you need further assistance.

    • 10
    • Reply
    • Share
      Share
      • Share onFacebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  4. unknown2016000 Teacher
    2020-01-31T17:09:07+00:00Added an answer about 3 years ago

    One possible solution to the problem of splitting, flattening, and repeating cells in certain columns within an array formula for Google Sheets would be to utilize built-in functions such as SPLIT and TRANSPOSE. The SPLIT function will break up each cell in a selected range by a specified delimiter, such as a comma or space, and place the resulting values into their own cells. A TRANSPOSE function can be then used to flip the resulting horizontal values into a vertical column format. Finally, any desired repetition of the values can be achieved by manipulating the resulting column of values using array truncation, concatenation or repetition.

    Another approach to this problem might be to use the QUERY formula in Google Sheets. The QUERY function can be utilized to select and transform a specific range of cells using SQL-like syntax, including table joins, calculations, and grouping functions. Within an array in Google Sheets, the QUERY function can be used to extract, concatenate, and repeat specified ranges from the array.

    Both of these solutions allow for customization of the output format, ease of use, and modularity of the formulas to accommodate future changes or updates.

    • 10
    • Reply
    • Share
      Share
      • Share onFacebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  5. nutrifit_ig Teacher
    2020-01-26T10:10:23+00:00Added an answer about 3 years ago

    I suggest using the `ARRAYFORMULA`, `SPLIT`, `FLATTEN`, and `REPT` functions to split flatten and repeat cells in certain columns within an array formula in Google Sheets. The `ARRAYFORMULA` wraps around the formula and performs calculations on the range of cells specified within the function brackets. The `SPLIT` function splits text into an array of substrings by recognizing a delimiter such as space or comma. The `FLATTEN` function combines the elements of one or more arrays into a single array. Finally, the `REPT` function repeats given text a specified number of times.
    To apply this method, enter the following formula in the first row of the cell where the results will appear:
    “`
    =ARRAYFORMULA(
    SPLIT(
    FLATTEN(
    REPT(A1:A4&”|”,2)&
    REPT(B1:B4&”|”,3)&
    REPT(C1:C4&”|”,4)&
    REPT(D1:D4&”|”,5)
    ),
    “|”
    )
    )
    “`

    In the formula above, `A1:A4`, `B1:B4`, `C1:C4`, and `D1:D4` represent the columns that will be split, flattened, and repeated according to the specified number of repetitions. The delimiter used in the `REPT` function is a vertical bar `”|”`, but any character can be used as long as it is not found in the original text. The `ARRAYFORMULA` wraps around the entire formula to ensure that it applies to the entire range of cells where the results are expected to appear.

    I hope this helps! Let me know if you have any questions.

    • 6
    • Reply
    • Share
      Share
      • Share onFacebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.