Using a Message Box to pick someone

  • Good weekend to you all,


    Basically I want a button that once pressed generate a message box that says a persons name. There are 3 names, so the message box should show name 1 1st and then when pressed again show name 2 and you guessed it then name 3!


    If anyone could let me know how to do this or have teh code that would be great

  • Re: Using a Message Box to pick someone


    Hi,


    Assign the macro X to your button
    [vba]Sub x()


    MsgBox "Name 1", vbOKOnly
    MsgBox "Name 2", vbOKOnly
    MsgBox "Name 3", vbOKOnly

    End Sub[/vba]

    [h4]Cheers
    Andy
    [/h4]

  • Re: Using a Message Box to pick someone


    Quote from stevehorton09

    Good weekend to you all,


    Basically I want a button that once pressed generate a message box that says a persons name. There are 3 names, so the message box should show name 1 1st and then when pressed again show name 2 and you guessed it then name 3!


    If anyone could let me know how to do this or have teh code that would be great



    After you add your button to the sheet, create the below macro and point the button to it.


  • Re: Using a Message Box to pick someone



    Andy,


    Won't this solution just show three messages (one after the other) with just one click of the button? Unless I read his post wrong, he wanted the name to change with each succesive click on the button itself...

  • Re: Using a Message Box to pick someone


    Quote from JF

    Andy,


    Won't this solution just show three messages (one after the other) with just one click of the button? Unless I read his post wrong, he wanted the name to change with each succesive click on the button itself...


    have you tested your code?

  • Re: Using a Message Box to pick someone


    : D I thought it was too simple a question. I just didn't read it right.


    So a variation on your post.
    [vba]Sub Buton1()

    Static clicknumber As Long

    clicknumber = clicknumber + 1
    MsgBox Choose(clicknumber, "Tom", "Sally", "Jane")
    If clicknumber > 3 Then clicknumber = 0


    End Sub[/vba]

    [h4]Cheers
    Andy
    [/h4]

  • Re: Using a Message Box to pick someone


    Quote from royUK

    have you tested your code?


    I ran it and it seemed to work. First Click showed Tom, next one showed "Sally" and the third click showed "Jane". On the 4th click, it started over again.

  • Re: Using a Message Box to pick someone



    I like it... your's is shorter and doesn't require the use of a public variable as well....

  • Re: Using a Message Box to pick someone



    Andy,


    Just noticed a problem with your's.. it errors after the third time... I modified it as follows and it seemed to correct it.


    Code
    Sub Buton1()
        
        Static ClickNumber As Long
        If ClickNumber > 3 Then ClickNumber = 1
        If ClickNumber = 0 Then ClickNumber = 1
        MsgBox Choose(ClickNumber, "Tom", "Sally", "Jane")
        ClickNumber = ClickNumber + 1
        
    End Sub
  • Re: Using a Message Box to pick someone


    just change 3---> 2

    Code
    Sub Buton1()
         
        Static clicknumber As Long
         
        clicknumber = clicknumber + 1
        MsgBox Choose(clicknumber, "Tom", "Sally", "Jane")
        If clicknumber > 2 Then clicknumber = 0
         
    End Sub

    If you walked away smiling-then for you the price was right

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!