0
votes

Hmm I have been on this for over 3 hrs I still haven't gotten the hang of it. I'm new to using Google scripts. So I want to loop through a range, get their values and use that to populate another sheet. I have been able to get the value for the first range but I want it to loop... I'm stuck...here is my code...

function va(){
  var app = SpreadsheetApp;
  var activeSheet = app.getActiveSpreadsheet().getActiveSheet();

  var ts = activeSheet.getRange("D4:D14").getValues();
  Logger.log(ts);

  var arr = [ts];
  var ss = app.getActiveSpreadsheet().getSheetByName("Tutor_Master's");
    ss.getRange("B11:B21").setValues(ts);
}
2
If you mean an onclick method, there is none. You can't just click somewhere and activate a trigger. onEdit works if you manually edit a cell and onChange if you copy something. But there is nothing that can detect a change to a different sheet or click in cell. - TheWizEd
Thanks for the info - JESN
Click what? Loop what? There's not much here to go on. stackoverflow.com/help/how-to-ask stackoverflow.com/help/mcve - tehhowch

2 Answers

0
votes

Try using the UI class. The documentation can be found here. I think using the 'alert' method of the UI class should work the way you want it to.

// Display "Hello, world" in a dialog box with an "OK" button. The user can 
// also close the
// dialog by clicking the close button in its title bar.
SpreadsheetApp.getUi().alert('Hello, world');

Though the 'prompt' method would also work well for you.

0
votes

Yeah, thanks. I kind of figured it out.

//Assign a value from TA to TM 
  for ( i = 4; i <= lastColumnTA; i++){
    for ( j = 4 ; j <= lastRowTA; j++){ 

        //Get TA value and TA period
        var ValueTA= TA.getRange(j, i).getValue();
        var cTAHv= TA.getRange(rTAHn, i).getValue();
        var rTAHv = TA.getRange(j, cTAHn).getValue();
        var TAperiod = cTAHv.substring(0, 3) + " " + rTAHv;

        //Get columNum for TMperiod to be Populated
        for ( A = 2; A <= lastColumnTM; A++){
        if(TAperiod == TM.getRange(1, A).getValue()){
           break;
           };
        };

      //Populate TM period
        TM.getRange(k, A).setValue(ValueTA);
        }; 
  };