+ Reply to Thread
Results 1 to 4 of 4

Repeated numbering within a column

Hybrid View

cmaskew Repeated numbering within a... 09-10-2010, 08:11 PM
Cutter Re: Repeated numbering within... 09-10-2010, 08:53 PM
stanleydgromjr Re: Repeated numbering within... 09-10-2010, 10:46 PM
cmaskew Re: Repeated numbering within... 09-11-2010, 09:51 AM
  1. #1
    Registered User
    Join Date
    09-10-2010
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2003
    Posts
    3

    Repeated numbering within a column

    I need a formula to return a text string along with a number and once the text string doesn't appear and then reappears in the column have the numbering start over again.

    For example in column A I have data:
    Employee
    Spouse
    Child
    Child
    Child
    Employee
    Child
    Employee
    Child
    Child

    I need the data to appear:
    Employee
    Spouse
    Child1
    Child2
    Child3
    Employee
    Child1
    Employee
    Child1
    Child2

    I have over 7,000 lines of relationship codes and need to number each child within a family.

  2. #2
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Repeated numbering within a column

    One way, involving 2 helper columns:

    With your sample shown in Column A starting in A1
    Place this formula in B2:

    =IF(AND(A2="Child",A1<>"Child"),1,IF(AND(A2="Child",A1="Child"),B1+1,""))
    Place this 2nd formula in C1:

    =A1&B1
    Drag this 2nd formula down to C2
    Now select Range B2:C2 and drag both formulas down as far as needed

    When done you can copy the C column and Paste Special - Values over the A column and then delete the B and C columns

  3. #3
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Repeated numbering within a column

    cmaskew,

    Welcome to the Excel Forum.


    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

    Adding the Macro
    1. Copy the below macro, by highlighting the macro code and pressing the keys CTRL + C
    2. Open your workbook
    3. Press the keys ALT + F11 to open the Visual Basic Editor
    4. Press the keys ALT + I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Paste the code by pressing the keys CTRL + V
    7. Press the keys ALT + Q to exit the Editor, and return to Excel
    8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


    
    Option Explicit
    Sub NbrChild()
    ' stanleydgromjr, 09/10/2010, EF745281
    Dim c As Range, a As Long
    Application.ScreenUpdating = False
    a = 0
    For Each c In Range("A1", Range("A" & Rows.Count).End(xlUp))
      If Trim(c) <> "Child" Then
        a = 0
      Else
        a = a + 1
        c = c & a
      End If
    Next c
    Application.ScreenUpdating = True
    End Sub

    Then run the "NbrChild" macro.
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  4. #4
    Registered User
    Join Date
    09-10-2010
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Repeated numbering within a column

    Thank you both!

+ 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