Reputation: 313
On the click on a Button I want a function to be triggered that copies the value from Sheet1!A6 to Sheet2!A6. (see template) ! What do I have to add to this to make it work?
function CopyPasteA6() {
var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
sheet.getRange('A6').value
???
}
Thanks for help!
Upvotes: 1
Views: 15599
Reputation: 46794
try like this, it's probably the simplest way to do it.
function CopyPasteA6() {
var sheet1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
var sheet2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2');
sheet1.getRange('A6').copyTo(sheet2.getRange('A6'))
}
then insert a drawing or an image in your sheet and assign the function to this image.
EDIT following your comment : this script copies to the next sheet if it exist. you'll have to put a button on each sheet though.... I'd suggest to use a menu instead that will be acessible from anywhere in the spreadsheet.
Note that 'A6' or "A6" are just the same ;-)
function CopyPasteA6() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var sheetidx = sheet.getIndex()-1 ;
var nextSheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[sheetidx+1];
sheet.getRange('A6').copyTo(nextSheet.getRange('A6'))
}
Upvotes: 1