bigr1822
bigr1822

Reputation: 27

How do I get the cell location (i,e A28)

Just started trying to teach myself google scripting. I have some names in a spreadsheet. I am trying to write a script that when I fill in any cell, if it finds that same name in the range I specify, it strikes a line through that cell with the same name.

This code below gets me the names, but I cant get the strike through to work. It is striking through cell "C3" and not in the ranged cells. Hope that makes sense. Please help!

function strikeThrough() {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var names = ss.getRange("A27:C29").getValues();
  var thename = ss.getRange("C3").getValue();
  var sheet = ss.getSheets()[0];  
  var arrayLength = names.length;

  for (var i = 0; i < arrayLength; i++) { 
    for (var k = 0; k < 3; k++) {   
      Browser.msgBox(names[i][k]);  
      if(names[i][k] == thename){
        ss.getActiveRangeList().setFontLine('line-through');     
      }
     }
  }
}

Upvotes: 0

Views: 72

Answers (1)

Cooper
Cooper

Reputation: 64032

Try this:

function strikeThrough() {
  var ss=SpreadsheetApp.getActiveSpreadsheet();
  var sh=ss.getActiveSheet();
  var nrg=sh.getRange('A27:C29');
  var names = nrg.getValues();
  var thename = sh.getRange("C3").getValue();
  for(var i=0;i<names.length; i++) { 
    for(var k=0;k<names[i].length;k++) {   
      if(names[i][k]==thename){
        sh.getRange(nrg.getRow()+i,nrg.getColumn()+k).setFontLine('line-through');  
      }
    }
  }
}

Upvotes: 1

Related Questions