google-apps-script Spreadsheet Service Copy a value from one sheet to current sheet

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Imagine that we have a separate Google spreadsheet, and we need to get the B2 cell value to cell D5 on your current sheet.

function copyValueandPaste()
{  
    var source = SpreadsheetApp.openById('spread sheet id is here'); //Separate spreadsheet book
    var sourcesheet = source.getSheetByName('Sheet1'); //Sheet tab with source data
    var sourceCellValue = sourcesheet.getRange('B2').getValue(); // get B2 cell value
    
    var thisBook = SpreadsheetApp.getActive(); // Active spreadsheet book
    var thisSheet = thisBook.getSheetByName('Sheet1'); // Target sheet
    thisSheet.getRange('D5').setValue(sourceCellValue); //Set value to target sheet D5 cell
}

You can find spreadsheet id from your URL.



Got any google-apps-script Question?