# Help: ARRAYFORMULA and COUNTA

**URL:** <https://community.glideapps.com/t/help-arrayformula-and-counta/6639>\
**Category:** Ask for Help\
**Created:** [April 8, 2020, 10:30pm UTC](https://community.glideapps.com/t/help-arrayformula-and-counta/6639 "2020-04-08T22:30:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JimHeiniger](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@JimHeiniger](https://community.glideapps.com/u/JimHeiniger)\
**Post date:** [April 8, 2020, 10:30pm UTC](https://community.glideapps.com/t/help-arrayformula-and-counta/6639/1 "2020-04-08T22:30:21Z")

</div>

In row D, I would like to count the values of row E (COUNTA) but only up the the current row of the column.  
I tried using ARRAYFORMULA and COUNTA and ROW, but from what I’ve read, COUNTA won’t work with ARRAYFORMULA.  
What I get with this formula is the total COUNTA of the column returned for each row.

 ![Screen Shot 2020-04-08 at 5.28.51 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/2X/e/e7ea8841491b87b323c4d3a025078e59e1b8ddc1.png)

---

<div class="post-metadata">

**Author:** ![JimHeiniger](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@JimHeiniger](https://community.glideapps.com/u/JimHeiniger)\
**Post date:** [April 9, 2020, 2:06am UTC](https://community.glideapps.com/t/help-arrayformula-and-counta/6639/2 "2020-04-09T02:06:17Z")

</div>

I figured it out! Turns out the solution is an app script. Here’s my code:

> function myFunction() {  
> var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();  
> ss.getRange(“D2”).setFormula(“=IF(ISBLANK($A2),COUNTA(INDIRECT($F2)))”);  
> var lr = ss.getLastRow();  
> var downRange = ss.getRange(2, 4, lr-1);  
> ss.getRange(“D2”).copyTo(downRange);  
> }

So if anyone is having difficulty getting ARRAYFORMULA to fill in the formula, just insert your formula as it would be in your top row, and change your destination in the getRange argument (change “D2”).

Also, my last row is set to lr-1 because I have a header row. If not, just do lr.
