FormulaCraft

How to auto-number rows that have data in Excel and Google Sheets

Topic:Data cleaning & shaping
Excel & Google Sheets
=IF(B2<>"",COUNTA($B$2:B2),"")

Verified example

Computed by a real spreadsheet engine on the sample data below.

#Name
Alice
Bob
Carol

=IF(B2<>"",COUNTA($B$2:B2),"")1

Try it with your data

Edit the grid or formula, then run it through a real spreadsheet engine — no signup.

Sample data — click any cell to edit

Runs server-side · free · no signup

Step by step

  1. 1In A2 (the number column), enter =IF(B2<>"",COUNTA($B$2:B2),"") — replace B with whichever column determines whether a row has data.
  2. 2Copy the formula down all rows in your data range.
  3. 3Blank rows in column B return an empty string in the number column; filled rows get a sequential count starting at 1.

Tips

Need it for your exact data?

Describe your columns in plain English and get the precise formula for your sheet, with the right Excel or Sheets syntax.

Frequently asked

What if I delete a row — do the numbers update?

Yes — because COUNTA recounts from the top each time, the sequence automatically closes any gap left by a deleted row.

Can I restart numbering for each group?

Yes — use COUNTIF: =IF(B2<>"",COUNTIF($C$2:C2,C2),"") where column C is the group label — this gives a per-group sequence number.

More on Data cleaning & shaping

See all →

Formulas used

Written and reviewed by FormulaCraft Team. Each formula on this page is run through our verification engine before publishing.

Last reviewed: