dimanche 4 août 2019

Creating An If Statement

My client wants to use Google Sheets instead of Excel. I could quickly write the code in VBA but am hitting a brick wall with Google Sheets.

H5 contains a drop-down list. I want the values in D5, D6, D7 and D8 to equal the value in H5 BUT only if a value has been selected in H5.

I have built my code based on similar examples I have seen on this website. I tried to debug my code but I didn't find the debugging tools in Google Sheets to be nearly as effective as in VBA.

function PercentageIncreases1() {

    var spreadsheet = SpreadsheetApp.getActive();

   var cell1 = ("H5");
   var cell2 = ("H6");
   var cell3 = ("H7");
   var cell4 = ("H8");

    if (cell1 > 0) {
  spreadsheet.getRange('D5').activate();
  spreadsheet.getCurrentCell().setFormula('=H5');
  spreadsheet.getRange('D6').activate();
  spreadsheet.getCurrentCell().setFormula('=H5');
  spreadsheet.getRange('D7').activate();
  spreadsheet.getCurrentCell().setFormula('=H5');
  spreadsheet.getRange('D8').activate();
  spreadsheet.getCurrentCell().setFormula('=H5');
    }



};

If the value in H5 is 10, then I expect the values in D5, D6, D7, D8 to also be 10.

At the moment the values in D5, D6, D7 and D8 are not being updated.

Aucun commentaire:

Enregistrer un commentaire