1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

creating autonumber in excel 2007 user form

Discussion in 'Business Applications' started by weboneau, Nov 26, 2008.

Thread Status:
Not open for further replies.
  1. weboneau

    weboneau Thread Starter

    Joined:
    Nov 26, 2008
    Messages:
    1
    I am creating a form for data input into an excel spreadsheet. The form just captures mail sent/received and the first text box is to be a unique number for every entry.

    Is there anyway that I can code the text box so that it puts in a unique number everytime a new record is added?

    I have attached my draft spreadsheet - it isn't finished yet as the next stage is to get excel to open automatically to the form.

    Cheers,
    B
     

    Attached Files:

  2. bomb #21

    bomb #21

    Joined:
    Jul 1, 2005
    Messages:
    8,546
    In your UserForm_Initialize:

    LastNumber = Application.Max(Sheets("MailRecords").Columns(1))
    txtNumber = LastNumber + 1

    Although ideally you should leave txtNumber off the form altogether. Just have Excel figure out new "Last Number" at the "Add Record" stage, thereby eliminating user "interference". IMO.
     
  3. bomb #21

    bomb #21

    Joined:
    Jul 1, 2005
    Messages:
    8,546
    Re Private Sub cbAdd_Click():

    Selecting MailRecords sheet, selecting cell A1, selecting the next cell down until you hit the first free one; no need for any of that. :)

    Private Sub cbAdd_Click()

    MR_Rows = Sheets("MailRecords").Range("A" & Rows.Count).End(xlUp).Row + 1
    Sheets("MailRecords").Cells(MR_Rows, 1) = Application.Max(Sheets("MailRecords").Columns(1)) + 1
    Sheets("MailRecords").Cells(MR_Rows, 2) = txtDate.Value


    And so on. :)
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/773214

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice