mardi 20 juin 2017

Google sheet script. how to write the else part of a statement to concatenate two cells

this is my first post. I have no previous knowledge of Google sheet programming, so please bear with me.

There are three columns that I am referencing. Column A is to receive the concatenated data from columns D and E, ie.

Column D entry = TrustName1, 
Column E entry = L83034, 
Column A entry = TrustName1 (L83034)
and I could achieve this in each cell using =D2 & " (" & E2 & ")"

However, some of the entries in Column D (which is data that is pulled from another source and cannot be changed) need tweaking before appearing in column A. To do this, I've created an 'if' statement script, below, and for those entries in column D that do not tweaking, I'd then like to say something along the lines of 'else, do =D2 & " (" & E2 & ")" for each other row of the whole spreadsheet.

Could somebody help me with this 'else' element, please? Much appreciated.

`function fillColA() {
  var s = SpreadsheetApp.getActiveSheet();
  var data = s.getDataRange().getValues();
  var data_len = data.length;
  for(var i=3; i<data_len; i++) 
 {
    if(data[i][3] == "A Practice") {
      s.getRange(i+1,1).setValue("A Surgery (L82000)");
      }

    if(data[i][3] == "B Surgery") {
      s.getRange(i+1,1).setValue("B Medical Practice (L81000)");
      }

    if(data[i][3] == "C Surgery") {
      s.getRange(i+1,1).setValue("C General Practice (L81001)");
      }
  }
}`

Aucun commentaire:

Enregistrer un commentaire