1

This seems like it should be very straight forward, but doesn't seem to be. Something like sheet.getRange(B2:2).getValues().filter(notBlank) but what do I put in place of notBlank?

1 Answer 1

1

In your situation, how about the following modification?

Modified script:

const res1 = sheet.getRange("B2:2").getDisplayValues()[0].filter(String).length;
console.log(res1)

// or
const res2 = sheet.getRange(2, 2, 1, sheet.getLastColumn() - 1).getDisplayValues()[0].filter(String).length;
console.log(res2)
  • In this case, I think that both getDisplayValues and getValues can be used.
  • By this, the number of cells that the cell value is not empty in "B2:2" is obtained.
Sign up to request clarification or add additional context in comments.

2 Comments

Ahh brill thankyou. I tried this initially but it didn't work because I didn't use [0] before filter. I think where I went wrong was I was assuming the result of getValues was a 1D array, but it's 2D, so the [0] was required to pull out the 1D row array
@jonnybolton16 Thank you for replying. Yes. In the case of "B2:B", when the value retrieved by getValues is like [["b2","c2","d2",,,]]. So, I used [0]. By this, it can be used as a 1-dimensional array.

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.