# Excel: Number Each Record for a Customer, Starting at 1 for a New Customer

This page is an advertiser-supported excerpt of the book, Power Excel 2010-2013 from MrExcel - 567 Excel Mysteries Solved. If you like this topic, please consider buying the entire e-book.

 Problem: I have a list of invoice data. I want to number the records in such a way that the first invoice number for Ford is 1. The next Ford invoice is 2, and so on. When I get to a new customer, I want to start over at 1. You want to add sequence numbers within each customer.

Strategy: Use a formula in a new column A to add the record number. Follow these steps.

1. Select one cell in the customer column and select Data, AZ to sort the data by customer.
2. Insert a new temporary column A and add the heading Rec # to A1.

In A2, enter the formula =IF(C2=C1,1+A1,1). In plain language, this formula says, "If the customer in C is equal to the customer above me, then add 1 to the cell above me. Otherwise, start at 1." Copy the formula down to all rows. Excel will number each group of customer invoices from 1 to N. When a new customer starts, the numbers will restart.

1. The live formulas work while the data is sorted.

Change the formulas in A using Ctrl+C, Home, Paste, Paste Values before sorting by invoice number.

Alternate Strategy: You can use the formula =COUNTIF(C\$2:C2,C2) without sorting.