2

I've got a sheet which I've used arrays to retrieve data and do some validations/calculations etc.

At the end of my code, I want to apply the updated values back to the sheet.

I've written this line.

shTest.getRange(1,1,sourceArray.length,sourceArray[0].length).setValues(sourceArray);

which works perfectly fine in applying the values of the full 2d array (which has 5 columns) to the sheet.

However I want to apply just the 5th column to column E in my sheet shTest (I declared shTest as a variable for my test sheet earlier in the code)

I got as far as this:

shTest.getRange(1,5,sourceArray.length,1).setValues(sourceArray);

But I couldn't workout how to amend the sourceArray part of my code (after .setValues) to specify that I want the data from the 5 column of the array.

1 Answer 1

3

In your situation, how about the following modification?

From:

shTest.getRange(1,5,sourceArray.length,1).setValues(sourceArray);

To:

shTest.getRange(1,5,sourceArray.length,1).setValues(sourceArray.map(r => [r[4]]));
  • By this modification, the values of column "E" (the 5 column in your question) are put to the column "E" of "shTest" sheet.

Reference:

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

1 Comment

@Michael Liew Thank you for replying. I'm glad your issue was resolved.

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.