+ Reply to Thread
Results 1 to 5 of 5

Adding line numbers within a group

  1. #1
    Registered User
    Join Date
    06-05-2013
    Location
    NYC
    MS-Off Ver
    Excel 2007
    Posts
    2

    Question Adding line numbers within a group

    I have a table in this format:

    Bob 5
    Bob 6
    Bob 19
    Alice 3
    Alice 26
    Alice 0
    Alice 8
    Alice 8
    Cory 3
    Cory 6

    I want to add line numbers that restart for each name, ie.

    Bob 5 1
    Bob 6 2
    Bob 19 3
    Alice 3 1
    Alice 26 2
    Alice 0 3
    Alice 8 4
    Alice 8 5
    Cory 3 1
    Cory 6 2

    Any ideas how I would do this?

    Thank you.

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Adding line numbers within a group

    =countif($a$1:$a1,$a1)

    and drag down.

    in which a1 is the name
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,212

    Re: Adding line numbers within a group

    Hi OcoBri and welcome to the forum,

    You have hit on one of the very useful formulas in Excel. It is:
    =COUNTIF(A$1:A2,A2)

    Find it in the attached and answers your question.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,319

    Re: Adding line numbers within a group

    Insert a blank row 1 if you don't have anything above your first Bob, then in C2 you can have this formula:

    =IF(A2<>A1,1,A1+1)

    then copy down.

    Hope this helps.

    Pete

  5. #5
    Registered User
    Join Date
    06-05-2013
    Location
    NYC
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Adding line numbers within a group

    Thank you all! COUNTIF worked.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1