• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

if statement / Case statement

helloakshay

New Member
Hi All

The user inputs a value and based on that there is some action like diffrent message boxes for different input values

Want to know if there is any simple way to write the below code. I have more than twenty such choices like "AB", "BC"......................... and so on.

Even in case statement i assume we need to write for each option
case "AB"
Do something
case "CD"
Do something

Instead of writing for each option is there any simpler way

[/CODE]
Dim pc As Variant
pc = InputBox("enter your choice")

If pc = "AB" Or "CD" Then
MsgBox "1234"
ElseIf pc = "EF" Or "GH" Then
MsgBox "4567"
Else
MsgBox "8910"

End If
 
Hi ,

Forget about the coding , and explain your requirement in detail.

You have 20 choices , from which the user can select / enter one ; what is to be the action taken for each of these 20 choices ?

Narayan
 
I have 20 -30 choices. user enters one of them in the input box
example "AB" / CD" / "EF". Based on the input it will give a particular message
 
i could solve my prob with the code below

Code:
Dim pc As Variant
pc = InputBox("enter your choice")

Select Case pc

Case "AB", "DE", "FG", "DE", "GF"
MsgBox 1234
Case 12, 23, 45, 77, 99, 25, 66
MsgBox "ABCD"
End Select
 
Back
Top