+ Reply to Thread
Results 1 to 5 of 5

Autonumber Until Certain Value then Restart

Hybrid View

  1. #1
    Registered User
    Join Date
    03-25-2013
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2007
    Posts
    13

    Autonumber Until Certain Value then Restart

    I hope I can articulate clearly what I'm trying to do.

    So I have a list of data that I do not know the length of in advance. I need to automatically number each entry (the entries themselves make no difference) to a certain number and then start back at one. So say I have a list of 9 entries and I want them to label 1, 2, 3, 4 and then on the 5th entry is starts back at one, then at the 9th entry it's 1 again and so on for longer lists. My mind just isn't wrapping around the code for this. I've attached a sample workbook with what I've thought of so far but I just don't even know where to begin to get it to start over. I've tried nested for-loops but I get errors....
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Autonumber Until Certain Value then Restart

    hi sperryxx, is this option acceptable? Or do you want to have loop code for the issue?

    Sub test()
    
    Dim lrow As Long
    
    lrow = Cells(Rows.Count, 3).End(xlUp).Row
    If lrow = 1 Then Exit Sub
    
    With Range("a2:a" & lrow)
        .Value = "=If(ROW(A1)=1,1,IF(MOD(A1,5)=0,1,A1+1))"
        .Value = .Value
    End With
    
    End Sub
    Change number (currently 5) to get different last group number

  3. #3
    Registered User
    Join Date
    03-25-2013
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Autonumber Until Certain Value then Restart

    Awesome, works beautifully, thank you! :]

    Although, looping might work for what I am going to have it evolve into later....

  4. #4
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Autonumber Until Certain Value then Restart

    option:

    Sub test()
    
    Dim lrow As Long, i As Long, j As Long
    
    lrow = Cells(Rows.Count, 3).End(xlUp).Row
    If lrow = 1 Then Exit Sub
    
    result = Range("a1:a" & lrow)
    
    For i = 2 To lrow
        j = j + 1
        If j > 5 Then j = 1
        result(i, 1) = j
    Next
    
    Range("a1:a" & lrow) = result
    
    End Sub

  5. #5
    Registered User
    Join Date
    03-25-2013
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Autonumber Until Certain Value then Restart

    YAY! Thank you :]

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Userform restart after end sub
    By Sibrulotte in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-13-2011, 02:34 PM
  2. Re: 'Do Until...' Restart
    By Jack in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-22-2006, 04:10 AM
  3. [SOLVED] Re: 'Do Until...' Restart
    By Jack in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-21-2006, 12:32 PM
  4. 'Do Until...' Restart
    By Jack in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-21-2006, 11:10 AM

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