I have data in multiple columns from rows 3-15. I want to find all the unique values in that data set and have it outputted in one column.
The unique function only does one column at a time so it does not work for my purposes.
I am writing a script that will open a new sheet and copy and paste the values into the same column (combines data from multiple columns into one longer column). I will then run the unique function on the single column containing all the data to get an output of all the unique values in my original dataset (Items!B3:Z15)
I have the code written but cannot figure out how to increment a character. If there is a better way to achieve this I am open to suggestions, but I am also curious if it is possible to increment letters.
Thanks for the help, here is my current code:
function uniqueIngredients() {
var book = SpreadsheetApp.getActiveSpreadsheet();
var r=1; // starting with row 1 new sheet
var d='B';
for (i=1; i<4; i++){ //testing by running 3 iterations
var m = 'Ingredients!A'+r; //Intially return Ingredients!A1 then incremented by 11 ex A12
var c = 'Items!'+d+'4:'+d+'15'; // Initially return Items!B3:B15 then incremented by letter ex Items!C3:C15
r = r+12; // add 12 spaces before next copy (max number of ingredients for each item)
d++;
book.getRange(c).copyTo(book.getRange(m), {contentsOnly:true});
}
};
You can use an alternative parameter specification for the getRange() method, which uses column numbers rather than A1 string notation. This would be easier to increment.
That being said, as you are copying values only, it would probably be better (more efficient) to get the source range in a block, and use Javascript to convert into a one-column array, and then set the values:
And that being said, you could use a bit of a workaround to provide the end result using spreadsheet functions only: