0

I'm trying to do what I thought was basic script. but alas i'm struggling.

In Column C I am trying to create a string of Column D & Column E with a space in the middle. as a formula I would use

=D18&" "&E18

as code I have

{function myFunction() {
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName("CP");
var cell = sheet.getRange("C:C");
cell.setFormula("=D:D&E:E");} 

which does combine the two cells but without a space. is this at all possible. It needs to be done in script because I have third party services connected to google sheets where the data comes in but the formula does not carry down.

Thanks Dan

2 Answers 2

2

Try

cell.setFormula('=Arrayformula(D:D&" "&E:E)')
Sign up to request clarification or add additional context in comments.

2 Comments

I tried this and although formula was brought through correctly as an array it errored because it was referencing itself
You can not use a formula referencing columns in those columns itself. The output should be okay when entered in column F (or any other column).
0

Try this:

function cde(){
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getSheetByName('CP');
  var rg=sh.getRange(1,3,sh.getLastRow(),3);
  var vA=rg.getValues();
  for(var i=0;i<vA.length;i++){
    vA[i][0]=String(vA[i][1]) + " " + String(vA[i][2]);
  }
  rg.setValues(vA);
}

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.