26

In a Google Docs Spreadsheet, I would expect this formula:

=ARRAYFORMULA(ROW())

to fill the column like:

[   1]
[   2]
[   3]
[   4]
  ...

but instead it stops at 1. What is happening here? Is there another way to get the current row number in an arrayformula?

4 Answers 4

30

You need to specify a cell-range argument for ROW() in order to have more than one value.

Try it this way:

=ARRAYFORMULA(ROW(A1:A10))

This will fill a column with row numbers from 1 to 10.

2
  • 2
    Thanks, this makes sense now! I wanted it to fill the sheet and expand when rows are added, so I used: =ARRAYFORMULA(ROW(A2:A)) (starting under the header row)
    – rymo
    Feb 24, 2012 at 18:20
  • If I need to be certain the numbers returned match the actual sheet row numbers they are on, but don't know which row the formula is starting on, is there a simpler method than this? =ARRAYFORMULA(ROW(INDIRECT(CONCATENATE("A",ROW(),":A"))))
    – rymo
    Feb 24, 2012 at 18:31
19

The following may be a little simpler:

=arrayformula(ROW(INDIRECT("A"&ROW()&":A")))

or

=index(ROW(INDIRECT("A"&ROW()&":A")))
0

This works when you want row number limited to not-empty row

=ARRAYFORMULA(filter(ROW(INDIRECT(CONCATENATE("A";ROW();":A")));A2:A<>""))
0

Put this on the 1st Column header

=arrayformula({"NO.";IFERROR(IF(B2:B<>"",ROW(INDIRECT("A"&ROW()&":A")),""))})

If you have an error saying:

"Circular dependency detected. To resolve with iterative calculation, see File > Settings."

Go to File > Settings > Calculation Tab > Iterative calculation

2
  • I have an error with this formula: "Circular dependency detected. To resolve with iterative calculation, see File > Settings." Jul 11 at 8:41
  • Go to File > Settings > Calculation Tab > Iterative calculation Jul 12 at 0:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.