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?

rymo
  • 3,285
  • 2
  • 36
  • 40

4 Answers4

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.

Warwick
  • 1,200
  • 12
  • 22
  • 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 '12 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 '12 at 18:31
19

The following may be a little simpler:

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

or

=index(ROW(INDIRECT("A"&ROW()&":A")))
Bo Persson
  • 90,663
  • 31
  • 146
  • 203
Yogi Anand
  • 434
  • 4
  • 3
0

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

=ARRAYFORMULA(filter(ROW(INDIRECT(CONCATENATE("A";ROW();":A")));A2:A<>""))
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Manack
  • 1
0

Put this on the 1st Column header

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