I created an array containing multiple rows and columns. In column B, I have the type of vegetables, and in column c, the varieties. In the array, there is an automatic sort
How about this sample script? I think that there are several answers for this situation, so please think of this as one of them. The flow of this script is as follows.
function myFunction() {
var start = 4; // Start row number for values.
var c = {};
var k = "";
var offset = 0;
var ss = SpreadsheetApp.getActiveSheet();
// Retrieve values of column B.
var data = ss.getRange(start, 2, ss.getLastRow(), 1).getValues().filter(String);
// Retrieve the number of duplication values.
data.forEach(function(e){c[e[0]] = c[e[0]] ? c[e[0]] + 1 : 1;});
// Merge cells.
data.forEach(function(e){
if (k != e[0]) {
ss.getRange(start + offset, 2, c[e[0]], 1).merge();
offset += c[e[0]];
}
k = e[0];
});
}
Composées, Cucurbitacées, Légumineuses, Liliacées, Solanacées
. On the other hand, the order of "Wish" is Composées, Cucurbitacées, Légumineuses, Solanacées, Liliacées
.
Liliacées, Solanacées
and Solanacées, Liliacées
.If I misunderstand your question, I'm sorry.
For your next question, I think that the following flow can achieve what you want. But I think that there may be other solution.
breakApart()
.
"sample", "sample", "sample"
. When this merged cell is broken using breakApart()
, each value of "A1:A3" retrieved by getValues()
becomes [["sample"],[""],[""]]
.breakApart()
.If you want to break "B1:B", please use as follows.
var ss = SpreadsheetApp.getActiveSheet();
ss.getRange("B1:B").breakApart()