I've used the record macro function to generate the following script.
I want the content of any active cell to be copy-pasted over to cell 'E2' in another sheet 'facture'. But I don't want getRange('\'orders/sales\'!C29')
. What should it be?
function invoice() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getCurrentCell().activate();
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('facture'), true);
spreadsheet.getRange('E2').activate();
spreadsheet.getRange('\'orders/sales\'!C29').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
};
(PS: I'm not a coder. Saw a few topics on the matter but all too complexe, hence my basic question)
CodePudding user response:
Just paste this code into your code editor and restart your Google Sheet document
function onOpen(e) {
SpreadsheetApp.getUi()
.createMenu('Admin Menu')
.addItem('Copy Active Cell', 'copyActiveCellValue')
.addItem('First Run - authorization', 'firstRun')
.addToUi();
}
function firstRun(){
SpreadsheetApp.getUi().alert('Autorization completed! You can use your script now.');
}
function copyActiveCellValue() {
var spreadsheetDocument = SpreadsheetApp.getActive();
var currentCellValue = spreadsheetDocument.getCurrentCell().getValue();
var spreadsheet2 = spreadsheetDocument.getSheetByName('facture').activate();
spreadsheet2.getRange(2,5).setValue(currentCellValue).activateAsCurrentCell();
}
After that, wait for "Admin Menu" to load in beside "Help", press "First Run" and approve authorization. After that, when you click on "Copy Active Cell" you will get value from active cell in the "E2" field on 'facture' sheet.