PDA

View Full Version : Solved: help with vba



patel51
11-27-2008, 09:17 PM
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;

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


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)!"

patel51
11-27-2008, 10:34 PM
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.

rbrhodes
11-27-2008, 11:42 PM
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:


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



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


X = Range("C5") & " has $ " & Range("C25")

patel51
11-28-2008, 12:39 PM
Sweet, thanks a ton!

rbrhodes
11-28-2008, 02:52 PM
Please marked as solved