Consulting

Results 1 to 9 of 9

Thread: Solved: Could you please help me to use VBA for random name

  1. #1
    VBAX Newbie
    Joined
    Nov 2011
    Posts
    5
    Location

    Solved: Could you please help me to use VBA for random name

    Dear Guru
    I have a project
    In December our company will to have New year party.
    I have requirement from staff.
    need to make program random employee ID number for receive prize
    But I don't know how to, If possible if someone have a code use by VBA could you please advice me.
    Becuase I don't have any expernince for EXCEL VBA
    < Concept >
    1. Make Sheet1 to keep ID number and Name.
    2. Sheet2 to make button on click to random ID Number from sheet1
    3. Random Timing 10 second
    4. When random fininsh show ID number and Name in sheet2
    (if ID number already receive prize 1 time status show " You already receive or ID Number is duplicate ")

    Could you please help
    Becuase I don't have any experince for make it.

    Thank you for all help me
    Regards

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Make a list of employees.
    Put =RAND() in the cells next to their names.
    Sort that 2 column range on the Rand column.
    The name at the top is the first one "drawn from the hat"
    The next name down is second, etc.

  3. #3
    VBAX Newbie
    Joined
    Nov 2011
    Posts
    5
    Location
    Quote Originally Posted by mikerickson
    Make a list of employees.
    Put =RAND() in the cells next to their names.
    Sort that 2 column range on the Rand column.
    The name at the top is the first one "drawn from the hat"
    The next name down is second, etc.
    Thank you very much for advice me.
    I am new member to use VBA and don't have any experience to make it.
    if possible could you please past the code for me.
    Sorry for inconvenience
    Please help me.

  4. #4
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    That isn't VBA, its native Excel.

  5. #5
    VBAX Newbie
    Joined
    Nov 2011
    Posts
    5
    Location
    Quote Originally Posted by mikerickson
    That isn't VBA, its native Excel.
    Now I already made Excel file.
    When need to random need to push F9, this Excel can random it

    If need to input Button to click for random. (Not push F9)
    How to make code in this button.
    Could please advice me

  6. #6
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Create your RAND as pointed out earlier on a worksheet then add a button from the forms toolbox, create a macro like this[VBA]Sub Calc_Rand()
    Application.CalculateFull
    End Sub[/VBA]and assign that macro to the button, its just like pressing F9
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  7. #7
    VBAX Newbie
    Joined
    Nov 2011
    Posts
    5
    Location
    Quote Originally Posted by Simon Lloyd
    Create your RAND as pointed out earlier on a worksheet then add a button from the forms toolbox, create a macro like this[vba]Sub Calc_Rand()
    Application.CalculateFull
    End Sub[/vba]and assign that macro to the button, its just like pressing F9
    Wow thank you very very much sir.
    And also I have another question :

    When click button Random , I need to running time for Random 10 Sec
    How to make code.

    Could you please help me
    Last edited by 42320135; 11-22-2011 at 08:49 PM.

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try this
    Attached Files Attached Files
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  9. #9
    VBAX Newbie
    Joined
    Nov 2011
    Posts
    5
    Location
    Quote Originally Posted by xld
    Try this
    Thank you very much sir....
    it greats excel sir,

    Regards

Posting Permissions

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