Consulting

Results 1 to 5 of 5

Thread: Solved: help with vba

  1. #1

    Solved: help with vba

    ok, i am trying to write a select case statement. depending on the case, i want to change the caption of another button to the correct value. so far this is what i have;

    [VBA]Select Case mintTurn
    Case "1"
    cmdRoll.Caption = "Roll the dice," & "Range(C5).Value" & "!"
    Case "2"
    cmdRoll.Caption = "Roll the dice," & "Range(E5).Value" & "!"
    End Select[/VBA]


    i have the values that i want already stored in cells C5 and E5, but how do i write the syntax so that if its case 1, then the caption will change to "Roll the dice, (whatever is stored in C5)!"

  2. #2
    also, how can i possibly do this:
    "<Player 1> has <$$>", where "<Player 1>" should be replaced by the content of cell C5 and "<$$>" should be replaced by the content of cell C25.

  3. #3
    VBAX Expert
    Joined
    Feb 2005
    Location
    Nanaimo, British Columbia, Cananda
    Posts
    568
    Location
    Hi Patel51,

    1) It's about the quotes. String values require them as in:

    "I'm a string"

    Range values require them around the address as in:

    Range("C5")

    and since '.Value' is the default you can write:

    [vba]
    Select Case mintTurn
    Case 1
    cmdRoll.Caption = "Roll the dice, " & Range("C5") & "!"
    Case 2
    cmdRoll.Caption = "Roll the dice, " & Range("E5") & "!"
    End Select

    [/vba]

    Note: if you want a space after the comma you must include it in the string value as above.

    Note2: if you want to include a " in a string it must be enclosed in "" ...!

    ie: "I'm a string with a """ in it!" will give you

    I'm a string with a " in it!


    2) Note the space between " and has and between has and $ " in the line below

    [vba]
    X = Range("C5") & " has $ " & Range("C25")
    [/vba]
    Cheers,

    dr

    "Questions, help and advice for free, small projects by donation. large projects by quote"

    http:\\www.ExcelVBA.joellerabu.com

  4. #4
    Sweet, thanks a ton!

  5. #5
    VBAX Expert
    Joined
    Feb 2005
    Location
    Nanaimo, British Columbia, Cananda
    Posts
    568
    Location
    Please marked as solved
    Cheers,

    dr

    "Questions, help and advice for free, small projects by donation. large projects by quote"

    http:\\www.ExcelVBA.joellerabu.com

Posting Permissions

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