0

I have code to calculate two cells by formula this is my code :

function myFunction() {
     var ss = SpreadsheetApp.getActiveSpreadsheet();
     var sh = ss.getSheetByName("sheet29");
     var maxR = sh.getMaxRows();

     var first = sh.getRange(maxR,6,1);
     var second = sh.getRange(maxR,7,1);

     var calculate = sh.getRange(maxR,8,1);

     first.setValue("2");
     second.setValue("2");

     var q = "F6"; // I want to change it to some thing like var q = first...;
     var qq =  "G6"; // I want to change it to some thing like var q = second...;

     var formula= ("=sum("+q+"+"+qq+")");
     calculate.setValue(formula);
 }

This code is fine calculate by formula by this code

var formula= ("=sum("+q+"+"+qq+")");
calculate.setValue(formula);

what I need, I don't know what is the name of cells to calculate, this dynamic. Any way to find the name of cell by range or another method

0

1 Answer 1

1

You can get the A1 notation of a range by using range.getA1Notation() method and use it to set formula. Change your code

From:

 var q = "F6";
 var qq =  "G6";

To:

 var q = first.getA1Notation();
 var qq =  second.getA1Notation();

Reference:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.