Google-sheets – User defined Series in Google Sheets

google sheets

I have a series which is like 1,1,1,1,1,1,1,2,2,2,2,2,2,2…

I have filled 1(*8) times and 2(*8) times, how do I continue this series by drag-drop option in Google Sheets?

Best Answer

We need to develop a custom function for doing the required tasks.

/* _val is the number of series you want
*  you want 166 series of the number which is like 166*8
*/ the function will fill 1328 rows

function myFunction(_val) {

  var data = [];

  for(var x =1 ; x < _val ; x++){
    // here 8 is the number of times you want the number to repeat
    for(var l = 0 ; l < 8 ; l++){
        data.push(x);
    }

  }
  return data;
}

Points to be noted:

  1. You can return a multidimensional array like [[1,2] [4,5]] to fill up multiple columns at a time // here the result will be Cell A will have 1,4 and B will have 2,5

  2. You can't use setValue() in a custom function