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.
Strategy: Use a formula in a new column A to add the record number. Follow these steps.
- Select one cell in the customer column and select Data, AZ to sort the data by customer.
- 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.
- 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.