+ Reply to Thread
Results 1 to 10 of 10

Auto Generation of number in sequential manner in textbox

  1. #1
    Registered User
    Join Date
    09-26-2016
    Location
    Dubai
    MS-Off Ver
    Excel 2013
    Posts
    24

    Auto Generation of number in sequential manner in textbox

    Hi
    I am new to VBA. I have to auto generate serial number in a textbox when the user enters the form. The number should be stored somewhere so that when the form is closed and is again opened it does not start with 1 again. Also, example the number generated is 5. So, whatever data the user entered should be placed in row 5 of the excel sheet. I know how to do that but the number generation is not happening.
    I searched a lot and even found links that could be called as duplicate of mine but nothing helped.
    Please help

  2. #2
    Valued Forum Contributor Neil_'s Avatar
    Join Date
    04-19-2013
    Location
    Yorkshire
    MS-Off Ver
    Office 365 Enterprise E3 2013 / 2016
    Posts
    479

    Re: Auto Generation of number in sequential manner in textbox

    Hi,
    here's one I made earlier.

    If it crashes complaining of a missing reference, there is a fix here - http://stackoverflow.com/questions/1...rform#17493134
    Attached Files Attached Files
    Frob first, tweak later

  3. #3
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Auto Generation of number in sequential manner in textbox

    If you want to place data into the first blank row, just use code like this:

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  4. #4
    Registered User
    Join Date
    09-26-2016
    Location
    Dubai
    MS-Off Ver
    Excel 2013
    Posts
    24

    Re: Auto Generation of number in sequential manner in textbox

    Hi.
    Thanks for the code but this part I know. I want to know how to generate serial number and print it in a textbox. once the form is closed it should start with the next number and not go to the first number.

  5. #5
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Auto Generation of number in sequential manner in textbox

    Then in the userform initialize event, Name a cell "SNumber" and use code like

    Please Login or Register  to view this content.

  6. #6
    Valued Forum Contributor Neil_'s Avatar
    Join Date
    04-19-2013
    Location
    Yorkshire
    MS-Off Ver
    Office 365 Enterprise E3 2013 / 2016
    Posts
    479

    Re: Auto Generation of number in sequential manner in textbox

    Or if you don't want to reference a worksheet....
    Please Login or Register  to view this content.
    Last edited by Neil_; 09-26-2016 at 12:48 PM.

  7. #7
    Valued Forum Contributor Neil_'s Avatar
    Join Date
    04-19-2013
    Location
    Yorkshire
    MS-Off Ver
    Office 365 Enterprise E3 2013 / 2016
    Posts
    479

    Re: Auto Generation of number in sequential manner in textbox

    or... You could leave this line out of Bernie's code if you set the Textbox controlSouce property to SNumber
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    09-26-2016
    Location
    Dubai
    MS-Off Ver
    Excel 2013
    Posts
    24

    Re: Auto Generation of number in sequential manner in textbox

    Hi,
    Its not working

    Private Sub CommandButton1_Click()
    Dim iRow As Long
    Dim full As String
    Dim r As Integer
    Dim ws As Worksheet
    Set ws = Worksheets("Sheet2")
    iRow = ws.Cells(Rows.Count, 1) _
    .End(xlUp).Offset(1, 0).Row

    r = Me.txtNum.Value
    Cells(r, 1).Select

    Call UserForm_Initialize
    End Sub

    Private Sub UserForm_Initialize()
    With txtNum
    .Value = Format(Val(Cells(Rows.Count, 1).End(xlUp)) + 2)
    .Enabled = False
    End With
    End Sub

    Now the problem is that the number is not being incremented.
    Please help

  9. #9
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Auto Generation of number in sequential manner in textbox

    The number will not increment until you put a value into the cell at the bottom of column A. You are basically counting the used rows based on column A....

  10. #10
    Registered User
    Join Date
    09-26-2016
    Location
    Dubai
    MS-Off Ver
    Excel 2013
    Posts
    24

    Re: Auto Generation of number in sequential manner in textbox

    Thank You! I was able to do it with your help!

+ 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. Auto Number Generation
    By abdul43 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-10-2014, 02:21 PM
  2. Auto invoice number generation?
    By alfgrey in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-02-2013, 08:38 PM
  3. Auto Sequential Invoice number on a duplicate sheet
    By learnerspermit in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-28-2013, 03:55 AM
  4. Run-time error '1004' with vba for sequential auto-number for database entries
    By Orestees in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 09-20-2012, 10:50 AM
  5. Auto Generate Sequential Invoice Number
    By jneldon in forum Excel General
    Replies: 1
    Last Post: 03-09-2009, 01:17 PM
  6. Sequential Job Code Generation
    By Sir Spike in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-27-2007, 01:11 AM
  7. How do I Auto Number a field in Excel - sequential PO#
    By Melinda in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-30-2005, 05:10 PM

Tags for this Thread

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