It is quite helpful in creating some questionnaire where the input feed is short.No need to write a big insert function statement in Excel instead, of VBA Case Statement is quite short.As we did not define anything for A we got an error message as Nothing Found. Step 8: Now, let’s test with any number or alphabet other than 1 to 3. Let’s enter 2 and see what comes up.Īs we can see above proverb stored in Case, 2 is showed in the message box. We will get a message where it will ask you to enter any word of your choice.Īs we have already defined some cases above with numbers, here we will enter any number from 1 to 3. Other than these number, we need to define the FALSE statement as well in the Else condition as shown below. Step 6: Now, the above statement is TRUE only between Case 1 to 3 numbers. Here we have selected 3 proverbs starting from Case 1 to 3 with the message box command MsgBox as shown below.Ĭase 2: MsgBox "What goes around, comes around" Step 5: Now, inside the Select Case loop for string A, write any proverb with a message box to pop up. Step 4: Now open a Select Case loop and end with End Select for defined string A.
Step 3: Now assign an Input Box to defined String with a sentence “ Enter Word of Your Choice”.Ī = InputBox("Enter Word of Your Choice") Step 2: Now, define a String where we will store the text values as shown below. Step 1: For this, open a new module from the Insert tab and write Subcategory in the name of the performed function as shown below. We will use Case to print different proverbs as a text statement. In a similar fashion in this example, we will use VBA Case to print text messages with the help of String. Other values will give below error message which we defined in Else Case Statement. Once we do, we will get the message as “ Incorrect Day”, as shown below, because there are only 7 days in a week. Step 9: Now, let’s enter any number other than from 1 to 7. We got the message that “ Day is Friday”, which was assigned to Case 5. We will get a message box that will ask to Enter Day of the Week, as shown below. Step 8: Once done then compile and run the code. And for this, too, we will use MsgBox and End Select it.
Step 7: Now comes the Else Statement part of the Case where we will write if any of the defined cases is not TRUE, then we will get Else Case statement message as “ Incorrect Day”. And to print all the cases into the text message box, we will use the MsgBox command with all the Cases from 1 to 7 individually for each day of the week, as shown below. Step 6: As we have 7 days in a week so starting from Monday as Case 1, considering Monday is the first day of work till the last day of the week, which is Sunday as Case 7. Step 5: Now, to integrate the defined Integer with Case, use the Select command as shown below. It will notify us to enter the case number in this box to get the answer. Step 4: Now assign an Input Box to the defined integer and input the box name with “ Enter Day of Week”, as shown below.