Please help me out. i am working on a project that requires me to copy and paste to different sheet base on cell value. for example if I have 3 sheets.The name of the first is man, the name of the second is woman and the name of the third is child. when i type a man in a specific cell let say C7, then code should copy the data sheet D1:j10 to sheet named man likewise if I type woman in C7, the code should copy D1:J!0 to sheet named woman and if type child into C7 the code should copy D!:J10 to sheet named child
function trans() {
let ss = SpreadsheetApp.getActiveSpreadsheet();
let shtIn = ss.getSheetByName("in");
let ssS = SpreadsheetApp.openById("17cRhuKX1jko");
let shtOut = ssS.getSheetByName("Data");
let responses = shtIn.getRange("D1::J10").getValues();
//responses is a 2d array that looks like this [[a],[b],[c]]
}
function initSettings_() {
return [{
bookId: '17cRhuKDDqjCRFcMKn6b1jko',
targetSheetName: 'MAN',
colIndex: 12
}, {
bookId: '
17cRhuKDDqjCRFcMKn6b1jko ',
targetSheetName: 'WOMANl',
colIndex: 13
}, {
bookId: '
17cRhuKDDqjCRFcMKn6b1jko ',
targetSheetName: CHILD',
colIndex: 14
}]
}
function run() {
const sheet = SpreadsheetApp.getActive()
.getSheetByName('data')
const data = sheet.getDataRange().getValues();
const settings = initSettings_();
settings.forEach(setts => {
const pData = prepareData_(data, setts.colIndex);
if (pData && pData.length)
SpreadsheetApp.openById(setts.bookId)
.getSheetByName(setts.targetSheetName)
.appendRow(pData)
});
sheet.getRange("E16:J60").clearContent();
}
/**
* @param {any[][]} array
*/
function prepareData_(array, colIndex) {
return array.map(row => row[colIndex])
.filter(item => item !== '')
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("data").getRange("D1:J10").clearContent();
}