简体   繁体   中英

copy data from specific cell in a sheet to another sheet

There are few queries which are somewhat similar but I'm unable to get a solution from those.

In my mainsheet I'm importing data from a webpage using Importdata function in the mainsheet. The data in the webpage changes every 5mins and so the cell value A50 changes every 5 mins in the mainsheet.

Now I want to write a google app scrip function that will copy the value from A50 of mainsheet to another sheet in the cell A1,A2,A3,A4,A5.......and so on and have a timestamp correspondingly in B1,B2,B3,B4,B5....and so on

You can use onEdit() trigger function to do this. When an edit happens in cell A50 check if cell and sheets are correct then read value and save into target sheet. Below code does that. Change the sheet names as shown in comment.

function onEdit(e) {
  // check if active range is A50 or not
  var rangeStr = e.range.getA1Notation();
  if (rangeStr != 'A50') return;
  // get Spreadsheet
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  // get sheets
  var mainSheetNames = ['main sheet name', 'main sheet name', 'main sheet name']; // change here
  var mainSheet = e.range.getSheet();
  if (mainSheetNames.indexOf(mainSheet.getName()) == -1) return;
  var targetSheet = ss.getSheetByName('target sheet name'); // change here
  // get value
  var value = e.value;
  // set values
  targetSheet
    .getRange(targetSheet.getLastRow() + 1, 1, 1, 2)
    .setValues([[value, new Date().toLocaleString()]]);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM