Home > Mobile >  Input data at scanner in cycle at Google Script for Google Sheets
Input data at scanner in cycle at Google Script for Google Sheets

Time:09-17

I want to set a "for" loop in the Google sheet to insert data in column A1, then in column B1. Next entry in column A2, B2. But selecting the next cell is not allowed. In general, if anyone knows how to set the procedure for entering data later in column A then B, maybe without a macro, please help me. Thanks :) Which I did....


function MCOMANDAV3() {
  var spreadsheet = SpreadsheetApp.getActive();
  var cell = spreadsheet.getRange('input!A2');
  var stop = spreadsheet.getActiveCell();
  var ui = SpreadsheetApp.getUi(); // Same variations.
  var ranges =  spreadsheet.getActiveRangeList().getRanges();
  for (cell; cell != stop; cell.getNextDataCell) {
      spreadsheet.getRange('2:2').activate();
  spreadsheet.getActiveSheet().insertRowsBefore(spreadsheet.getActiveRange().getRow(), 1);
  spreadsheet.getActiveRange().offset(0, 0, 1, spreadsheet.getActiveRange().getNumColumns()).activate();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('input'), true);
  spreadsheet.getRange('A2').activate();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('rezultat'), true);
  spreadsheet.getRange('A2').activate();
  spreadsheet.getRange('input!A2').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('input'), true);
  spreadsheet.getRange('A3').activate();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('rezultat'), true);
  spreadsheet.getRange('B2').activate();
  spreadsheet.getRange('input!A3').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('input'), true);
  spreadsheet.getRange('2:2').activate();
  spreadsheet.getActiveSheet().deleteRows(spreadsheet.getActiveRange().getRow(), spreadsheet.getActiveRange().getNumRows());
  spreadsheet.getRange('2:2').activate();
  spreadsheet.getActiveSheet().deleteRows(spreadsheet.getActiveRange().getRow(), spreadsheet.getActiveRange().getNumRows());
  }
}


CodePudding user response:

function onEdit(event){
  var sh = event.source.getActiveSheet();
  var cell = event.source.getActiveRange();
  if (sh.getName()=='mySheet' && cell.getColumn()<3){
    var row=cell.getRow()
    if (cell.getColumn()==1){
      sh.getRange('B' row).activate()
    }
    else {
      sh.getRange('A' (row 1)).activate()
    }
  }
}

https://docs.google.com/spreadsheets/d/1GkIPFv5FeJ8VjjI-pgBddim7SRsCcCCbhhdJ3g2R8G8/edit?usp=sharing

  • Related