# Sheet formula is not working on newly created row

**URL:** https://community.glideapps.com/t/sheet-formula-is-not-working-on-newly-created-row/9941
**Category:** Ask for Help
**Created:** [May 28, 2020, 5:31pm UTC](https://community.glideapps.com/t/sheet-formula-is-not-working-on-newly-created-row/9941 "2020-05-28T17:31:59Z")
**Posts on this page:** 5
**Page:** 2

<div class="post-metadata">

### Author: ![mrdobelina](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mrdobelina/32/2308_2.png) [@mrdobelina](https://community.glideapps.com/u/mrdobelina)
#### Post date: [May 30, 2020, 7:55am UTC](https://community.glideapps.com/t/sheet-formula-is-not-working-on-newly-created-row/9941/23 "2020-05-30T07:55:33Z")

</div>

Hello, sure, there you go

> **[Distances Test](https://docs.google.com/spreadsheets/d/1V5ThW3AZlf0d8erTymUB8BIeSkjCBoDKP60dbTsjYTk/edit?usp=sharing)**
>
> Distances
> 
> Destination,Leaving from,Distance in meters
> Vicenza,Rome,,
> Falling waters,New York,4515605,4,516
> Ride along the coast,San Francisco,24434,24
> Salvation Mountain,San Diego,330087,330
> Surf in Santa Monica,Los Angeles,27328,27

As before, the first row will remain empty, and actually the formula on C:C I had to copy it manually as it wasn’t updating in the newly created row

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [May 30, 2020, 8:16am UTC](https://community.glideapps.com/t/sheet-formula-is-not-working-on-newly-created-row/9941/24 "2020-05-30T08:16:42Z")

</div>

Firstly in your formula, you have to write it like this:

```
=DrivingMeters(A2,B2)

```

Instead of:

```
=DrivingMeters(A2:A,B2:B)

```

Then, in column D, which I will call “Kilometers”, you are trying to use an Arrayformula on the header cell, which can’t compute a division over 1000 since it’s a text. You have to pass it like this for the column to work on rows with numerical data.

```
={"Kilometers";ARRAYFORMULA(IF(C2:C<>"",C2:C/1000,""))}

```

I have modified the script a bit. It should now work.

```
function fillFormula() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var spreadsheet = ss.getSheetByName("Distances");
spreadsheet.getRange('C2').activate();
spreadsheet.getCurrentCell().getNextDataCell(SpreadsheetApp.Direction.DOWN).activate();
var lr = spreadsheet.getCurrentCell().getRowIndex();
spreadsheet.getRange("C"+(lr)).autoFillToNeighbor(SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES);}
```

---

<div class="post-metadata">

### Author: ![mrdobelina](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mrdobelina/32/2308_2.png) [@mrdobelina](https://community.glideapps.com/u/mrdobelina)
#### Post date: [May 30, 2020, 12:08pm UTC](https://community.glideapps.com/t/sheet-formula-is-not-working-on-newly-created-row/9941/25 "2020-05-30T12:08:44Z")

</div>

Awesome! It works perfectly, now. Thank you so much — learnt something new.

---

<div class="post-metadata">

### Author: ![mrdobelina](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mrdobelina/32/2308_2.png) [@mrdobelina](https://community.glideapps.com/u/mrdobelina)
#### Post date: [May 31, 2020, 12:08pm UTC](https://community.glideapps.com/t/sheet-formula-is-not-working-on-newly-created-row/9941/26 "2020-05-31T12:08:35Z")

</div>

Sorry to bother, but actually it’s not working. I checked and double checked if I found any differences from the sample you made, but I can’t find any. And it’s not loading the script on a newly added row.

Since I have to submit it to the app store (the app is actually already in the Glide store, but I want to add this feature), can I share you the sheet to please have a look in the “production” file?

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [May 31, 2020, 12:14pm UTC](https://community.glideapps.com/t/sheet-formula-is-not-working-on-newly-created-row/9941/27 "2020-05-31T12:14:05Z")

</div>

Yeah send me a private message, I will try to find the error.

[Previous page](https://community.glideapps.com/t/sheet-formula-is-not-working-on-newly-created-row/9941.md?page=1)
