Results 1 to 5 of 5

Thread: Auto serial number
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Jun 2016
    Posts
    125
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Auto serial number

    Hello,

    Please I need your help, if this is any possible way in Excel

    I have a userform to show data on a list box, add new data to the sheet, and remove any selected row from the list box and the sheet
    I have all these buttons and codes working well, and I have uploaded my test file below

    At the moment, if (for example) I removed "Row7", the sort code will run and "Row8" data will be in "Row7" and will have the same serial number "4"

    What I'm looking for is:
    • ex: If I removed "Row 7" that has a serial number "3", then...
    • Run the sort code, then...
    • "Row8" data will be in "Row7" but with serial number "3"


    In conclusion, I need column "B" to always has a serial number

    here is my test file
    https://drive.google.com/file/d/1Qso...ew?usp=sharing

  2. #2
    Board Regular
    Join Date
    Aug 2018
    Posts
    56
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Auto serial number


  3. #3
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    29,119
    Post Thanks / Like
    Mentioned
    483 Post(s)
    Tagged
    49 Thread(s)

    Default Re: Auto serial number

    @Bering
    Can you please post your suggestion to the board, so that everyone can see it without having to download a workbook.
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  4. #4
    Board Regular
    Join Date
    Mar 2013
    Posts
    814
    Post Thanks / Like
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Auto serial number

    One way would be to use a formula for the Num's in column "B"
    =Row() - 4
    and when adding write the formula instead of an actual number to column B

  5. #5
    Board Regular
    Join Date
    Aug 2018
    Posts
    56
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Auto serial number

    Quote Originally Posted by Fluff View Post
    @Bering
    Can you please post your suggestion to the board, so that everyone can see it without having to download a workbook.
    Sorry Fluff:

    Module1

    original code
    Code:
    Sub SortList()With Sheet1
    .Range("B4:G9999").Sort key1:=.Range("B4"), order1:=xlAscending, Header:=xlNo
    End With
    End Sub
    my attempt
    Code:
    Sub SortList()Const IncrementalFactor As Integer = 1
    Const FirstRow As Integer = 6
    
    
    With Sheet1
    .Range("B4:G9999").Sort key1:=.Range("B4"), order1:=xlAscending, Header:=xlNo
    
    
    If .Cells(5, 3) <> "" Then
    
    
    .Cells(5, 2) = IncrementalFactor
    
    
    Else
    
    
    .Cells(5, 2) = ""
    
    
    End If
    
    
        For i = FirstRow To .Cells(.Rows.Count, 3).End(xlUp).Row
    
    
            .Cells(i, 2) = .Cells(i - 1, 2) + 1
        
        Next i
        
    End With
    End Sub
    I have also added a On Error Resume Next in the UserForm1 macro to prevent any error if all rows get deleted:
    Code:
    Private Sub cmdRemove_Click()
    On Error Resume Next
    The issue is in the row below:
    Code:
    ListBox1.RowSource = Sheet1.Range("Items").Address(external:=True)

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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