PDA

View Full Version : Select Case Function on a CommandButton/ToggleButton



Keziah
01-17-2017, 05:44 AM
Dear Community,

I have the following issue. My code works however in order to activate it I have to press the button twice. I checked it with a toggle button and a commandbutton, still no change.

Option Explicit
Dim result As String
Dim score As String



Private Sub CommandButton1_Click()
Range("B1").Value = result
score = Range("A1").Value


Select Case score
Case Is = "Abnehmen"
result = "Da wo ein Wille ist auch ein Weg, viel Erfolg beim Abnehmen"
Case Is = "Zunehmen"
result = "No Pain no Gain, viel Erfolg beim Zunehmen"
Case Is = "Halten"
result = "Top, scheint so als hättest du dein Ideal Gewicht gefunden"
End Select
End Sub

Maybe one of you can help me with this problem

Cheers,

Keziah

GTO
01-17-2017, 06:13 AM
I am not certain what you are trying to say in "...to activate it...", but shouldn't the code be more like:



Option Explicit

Private Sub CommandButton1_Click()
Dim result, score

score = Range("A1").Value

Select Case score
Case Is = "Abnehmen"
result = "Da wo ein Wille ist auch ein Weg, viel Erfolg beim Abnehmen"
Case Is = "Zunehmen"
result = "No Pain no Gain, viel Erfolg beim Zunehmen"
Case Is = "Halten"
result = "Top, scheint so als hättest du dein Ideal Gewicht gefunden"
End Select

Range("B1").Value = result

End Sub


Hope that helps,

Mark

Keziah
01-17-2017, 06:38 AM
Thanks Mark,

you solved my issue. What made the change was writing Range("B1").Value = result after end select

Cheers,

Keziah

snb
01-17-2017, 06:46 AM
Oder einfach so:

Private Sub CommandButton1_Click()
cells(1,2)=choose(instr("AZH",left(cells(1),1)),"Da wo ein Wille ist ist auch ein Weg, viel Erfolg beim Abnehmen","No Pain no Gain, viel Erfolg beim Zunehmen","Top, scheint so als hättest du dein Idealgewicht gefunden")
End Sub

GTO
01-17-2017, 06:50 AM
Glad to help and an easy fix :)