1
votes

I want to repeat the range of items multiple times (Value provided).

e.g.

I have this in a sheet1!A

Detroit
Texas
Utah
California 

Now I want to repeat them 3 times to get the output at Sheet2!A like:

Detroit
Texas
Utah
California 
Detroit
Texas
Utah
California 
Detroit
Texas
Utah
California 

What should be the formula?

I got this formula:

https://www.excel-bytes.com/how-to-repeat-a-range-of-items-multiple-times-in-excel/

But it's not working in Google Sheets

3
The original formula worked fine for me - the only issue I had with it was that it had the wrong sort of double quotation marks and I had to edit those =IF(ISBLANK(INDIRECT(“Cities!A”&ROW(A2))),INDIRECT(“Repeat!A”&(ROWS($A$2:A2)-(COUNTA(Cities!A:A)-2))),Cities!A2)Tom Sharpe
@player0 spreadsheet is for questions about spreadsheet apps that don't have an specific tag.Rubén

3 Answers

1
votes

this will work only if you paste it into A5 of the same sheet and drag it down:

=IF(ISBLANK(INDIRECT(ROW(A1))),INDIRECT((ROWS($A$1:A4)-(COUNTA(A:A)-2))),A1)

enter image description here

otherwise, you can use:

=QUERY({Sheet1!A1:A4;Sheet1!A1:A4;Sheet1!A1:A4},"select *",0)

or:

=TRANSPOSE(SPLIT(REPT(JOIN(",",Sheet1!A1,Sheet1!A2,Sheet1!A3,Sheet1!A4&","),3),",",1))

or:

=TRANSPOSE(SPLIT(REPT(Sheet1!A1&","&Sheet1!A2&","&Sheet1!A3&","&Sheet1!A4&",",3),",",1))

or:

function REPEAT(range,amount,header) {
  var output = [];

  // check if range is cell
  if(typeof range == 'string') {
    for(var i=0; i<amount; i++) {
      output.push([range]);
    }
    return output;
  } else {
    // check if header is wanted
    var value;
    if(header == 1) {
      output.push(range[0]);
      value=header;
    } else if(header == "") {
      value=0;
    } else {
      value=0;
    }  
    for(var i=0; i<amount; i++) {
      for(var j=value, jLen=range.length; j<jLen; j++) {
        output.push(range[j]);
      }
    }    
    return output;
  }  
}

=REPEAT(Sheet1!A1:A4,3,0)
0
votes

I might as well add this as an answer:

=IF(ISBLANK(INDIRECT("Cities!A"&ROW(A2))),INDIRECT("Repeat!A"&(ROWS($A$2:A2)-(COUNTA(Cities!A:A)-2))),Cities!A2)

works fine in Google Sheets and Excel.

This also works and may be preferable in Excel to avoid the use of Indirect:

=IF(ISBLANK(INDEX(Cities!A:A,ROW(A2))),INDEX(Repeat!A:A,ROWS($A$2:A2)-(COUNTA(Cities!A:A)-2)),Cities!A2)
0
votes

You might copy down from Row1:

=offset(Sheet1!A$1,mod(row()-1,4),)

for as many sets of four as suits you.