• Excel Book Excerpt

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

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

Number Each Record for a Customer, Starting at 1 for a New Customer

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.


Figure 732 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.


Figure 733 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.

<-Previous Topic Next Topic->

For more resources for Microsoft Excel:

privacy policy