+ Reply to Thread
Results 1 to 9 of 9

I need a random number within a range, and not to duplicate the numbers in current list

  1. #1
    Registered User
    Join Date
    07-09-2013
    Location
    Wausau, Wisconisn
    MS-Off Ver
    Excel 2010
    Posts
    19

    I need a random number within a range, and not to duplicate the numbers in current list

    Hi all! Here is what I am doing. Our students have a alternate student number which is what they use for email, computer login, etc... the syntax is the first four numbers are 1010 and the last four are the variable...for example 10102342 is one student and 10102393 could be a another student. The range is 10100001-10109999. I currently have just under 1000 students with 1010#'s already, so I would like to create a button on a form that would generate a 1010xxxx number without duplicating the current numbers.

    screenshot.png

    Thanks in advance!!

    My form has a text box (txtGenerate) which is the output; where the 1010# should show up. A command button (cmdGenerate) which is where the user will interact and click the button to generate the 1010#..
    Last edited by jmeddaugh; 07-09-2013 at 10:48 AM.

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: I need a random number within a range, and not to duplicate the numbers in current lis

    jmeddaugh,

    Welcome to the forum!
    Why a textbox? A user can manually change its contents. I think it would be better if you used a label. So assuming you replace the textbox with a label named lblGenerate, something like this snippet should work for you:
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    07-09-2013
    Location
    Wausau, Wisconisn
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: I need a random number within a range, and not to duplicate the numbers in current lis

    Thanks tigeravator, I really appreciate your expertise!!

    I got a compile error: method or data member not found.

  4. #4
    Registered User
    Join Date
    07-09-2013
    Location
    Wausau, Wisconisn
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: I need a random number within a range, and not to duplicate the numbers in current lis

    It worked, I just need to change my textbox to a label box, and rename it to lblGenerate.

    Thanks!!!

  5. #5
    Registered User
    Join Date
    07-09-2013
    Location
    Wausau, Wisconisn
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: I need a random number within a range, and not to duplicate the numbers in current lis

    Could I create a button to insert the data into the spreadsheet. I could create text boxes for SchoolName, Fname, LName, GR and maybe a check box for "is currently enrolled"?
    I don't want to ask for tooo much, but would you know the code to insert that data in the current spreadsheet??

    Would I have to change the lblGenerate to a textbox so the data can be inputed into spreadsheet?
    Other than that I have:
    txtFname - Last Name
    txtLname - First Name
    txtGrade - Grade Level
    chkEnroll - checkbox for enrolled
    cmdSubmit - submit to spreadsheet (assuming where the code will go)
    Last edited by jmeddaugh; 07-09-2013 at 01:32 PM.

  6. #6
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: I need a random number within a range, and not to duplicate the numbers in current lis

    jmeddaugh,

    It would probably look something like this:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    07-09-2013
    Location
    Wausau, Wisconisn
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: I need a random number within a range, and not to duplicate the numbers in current lis

    This is working great. Is there a way I can not have it choose the 9000-9999 range. I would like to use that range just for the staff, which I can do manually. Thanks in advance!!

  8. #8
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: I need a random number within a range, and not to duplicate the numbers in current lis

    jmeddaugh,

    In your cmdGenerate_Click code, specifically this line:
    Please Login or Register  to view this content.
    Change the 9999 to 8999

  9. #9
    Registered User
    Join Date
    07-09-2013
    Location
    Wausau, Wisconisn
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: I need a random number within a range, and not to duplicate the numbers in current lis

    Oh ya....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