+ Reply to Thread
Results 1 to 7 of 7

Code to provide unique number when macro button is clicked to open UserForm

  1. #1
    Registered User
    Join Date
    08-20-2012
    Location
    Glasgow
    MS-Off Ver
    Excel 2007
    Posts
    77

    Code to provide unique number when macro button is clicked to open UserForm

    Hi,

    I have a spreadsheet with two UserForms.

    One UserForm adds records.

    One UserForm allows users to views/edit records - this is a dropdown based on each row having a Unique Reference number entered at the Add Record stage.

    The code for the 'Add Record' UserForm is below, it all works fine and achieves its purpose.

    The only way you can add to the spreadsheet is by hitting the Add Record button.

    However, I want to create a function that automatically assigns a Unique number to the spreadsheet once the Add Record button is pressed even if, for example, someone goes in and manually deletes a line. The 'Unique Reference Number' is at the moment manually entered and falls under 'NameTextBox' in the code below.

    Any help is greatly appreciated.

    David


    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Code to provide unique number when macro button is clicked to open UserForm

    You can read the number of last record, then increment it
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    08-20-2012
    Location
    Glasgow
    MS-Off Ver
    Excel 2007
    Posts
    77

    Re: Code to provide unique number when macro button is clicked to open UserForm

    Do you have any code that I could use for this? and where to enter it?

    I am very new to this, have bundled along until this point.

    Many Thanks

    David

  4. #4
    Forum Contributor
    Join Date
    08-21-2008
    Location
    Hamilton, New Zealand
    MS-Off Ver
    Office 2007
    Posts
    255

    Re: Code to provide unique number when macro button is clicked to open UserForm

    try ..
    Please Login or Register  to view this content.
    and change NameTextBox.locked to True
    or remove the NameTextBox completely and use ...
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-20-2012
    Location
    Glasgow
    MS-Off Ver
    Excel 2007
    Posts
    77

    Re: Code to provide unique number when macro button is clicked to open UserForm

    Hi,

    thanks for this, I am very new to this, where abouts would I put this in my code?

    Many Thanks

    David

  6. #6
    Forum Contributor
    Join Date
    08-21-2008
    Location
    Hamilton, New Zealand
    MS-Off Ver
    Office 2007
    Posts
    255

    Re: Code to provide unique number when macro button is clicked to open UserForm

    using your code it would be as follows (see highlighted lines) ....
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-20-2012
    Location
    Glasgow
    MS-Off Ver
    Excel 2007
    Posts
    77

    Re: Code to provide unique number when macro button is clicked to open UserForm

    Great Thanks!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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