C
C
cosmo34522022-02-16 13:47:21
Google Sheets
cosmo3452, 2022-02-16 13:47:21

How to make a checkout in google spreadsheet?

I created a table, it has lines where the product code, name, price and quantity are indicated. Also in this table there is a cell where I enter the product code.
The task is to make sure that when the entered code and the product code match, the counter in the line of this product becomes one more

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
twobomb, 2022-02-16
@cosmo3452

Add a macro to your table, here is the code.
All documentation on Google Sheets Macros is here https://developers.google.com/apps-script/reference/

function myFunction() {
  var spreadsheet = SpreadsheetApp.getActive();  
  let region = "A1:B10";//Диапазон рабочей области
  let numbersCol = 1;//Порядковый номер колонки в диапазоне region по которой идёт поиск
  let countCol = 2;//Порядковый номер колонки в диапазоне region с количеством товара
  let range = spreadsheet.getRange(region);
  let ui = SpreadsheetApp.getUi();
  var response = ui.prompt('+1 к количеству', 'Введите номер товара', ui.ButtonSet.OK_CANCEL);
  if (response.getSelectedButton() == ui.Button.OK) {
    if(range.getRow() <= range.getLastRow())
      for(let i = 1; i <= range.getNumRows();i++){  
        if(range.getCell(i,numbersCol).getValue().toString().trim() == response.getResponseText().trim()){
          let v = parseInt(range.getCell(i,countCol).getValue());
          if(isNaN(v))
            v = 0;
          v++
          range.getCell(i,countCol).setValue(v);
          break;
        }        
        if( i == range.getNumRows())
          ui.alert("Товар с номером '"+response.getResponseText().trim() +"' не найден!")
      }
  }
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question