Here's an simplified example of what I am trying to do.
cat 2
dog 3
Translated to:
cat
cat
dog
dog
dog
Is that possible with just a function in a cell or do I have to use something like a macro? How would I do that?
Here's an simplified example of what I am trying to do.
cat 2
dog 3
Translated to:
cat
cat
dog
dog
dog
Is that possible with just a function in a cell or do I have to use something like a macro? How would I do that?
In Google sheets, assuming dog and cat are in A1 and A2 and 2 and 3 are in B1 and B2, this will do it:
=transpose(split(rept(A1&" ",B1)&rept(A2&" ",B2)," "))
In Google sheets, assuming "dog 2" and "cat 3" are in A1 and A2, this will do it:
=transpose(QUERY({(split(rept(split(A1," ")&" ",query(split(A1," "), "SELECT Col2"))," ")),(split(rept(split(A2," ")&" ",query(split(A2," "), "SELECT Col2"))," "))},,))
Credit:
G4mo in StackOverflow How to make a range repeat n-times in Google SpreadSheet
In Excel, you can use either VLOOKUP()
or a combination of INDEX()
and MATCH()
.
With data in cols A and B, in C1 enter 1 and in C2 enter:
=C1+B1
and copy downward. In D1 enter:
=IF(ROWS($1:1)>SUM(B:B),"",INDEX(A:A,MATCH(ROWS($1:1),C:C,1)))
and copy downwards:
The helper column D translates the repetition factor in column B into match index.
(Placing a helper column to the left of the data would allow the use of VLOOKUP()
)