Home /
Expert Answers /
Computer Science /
10-complete-in-excel-and-show-all-of-your-work-question-10-note-there-are-four-parts-to-pa213
(Solved): 10. Complete in Excel and show all of your work
Question 10: NOTE: There are four parts to ...
10. Complete in Excel and show all of your work
Question 10: NOTE: There are four parts to number 10. - Question 10: Use the If...Then...EIseIf statement in VBA code for the conditions on the slide "The If...Then...ElseIf Example 10." - Question 10A: Write the code based on Example 10a and compare with Example 10 results. - Question 10B: Write the code based on Example 10b and compare with Example 10 and 10 a results. - Question 10C: Write the code based on Example 10c to include trailing else. - Note: Please run all codes to make sure all message boxes work properly.
The If...Then...Elself Example 10 Sub Example10() Dim x As Integer x= InputBox("Enter an Integer Number. ", "Example 1", 100) If x<1000 Then MsgBox "Your number is smaller than 1000." Elseif x<2000 Then MsgBox "Your number is smaller than 2000." Elseif x<3000 Then MsgBox "Your number is smaller than 3000." Elseif x<4000 Then MsgBox "Your number is smaller than 4000." End If
Contrast the Preceding Code Example 10a To This Code Without the Elseif Sub Example10a() Dim x As Integer x= InputBox("Enter an Integer Number. ", "Example 1", 100) If x<1000 Then MsgBox "Your number is smaller than 1000." End If If x<2000 Then End If If x<3000 Then MsgBox "Your number is smaller than 3000." End If If x<4000 Then is smaller than 2000." MsgBox "Your number is smaller than 4000." End If End Sub If 4022/ Ga2 Infnrmation Guctom fnr If
Does Reversing the Order of the Conditions Work? Example 10b Sub Example10b() Dim x As Integer x= InputBox("Enter an Integer Number. ", "Example 1", 100) If x<4000 Then MsgBox "Your number is smaller than 4000." Elseif x<3000 Then MsgBox "Your number is smaller than 3000." Elseif x<2000 Then MsgBox "Your number is smaller than 2000." Elseif x<1000 Then MsgBox "Your number is smaller than 1000." End If
- A sequence of Elselfs may end with a plain else (called a trailing Else) - If none of the conditions were True, the statement(s) after this Else will be executed Sub Example10c() Dim × As Integer x= InputBox("Enter an Integer Number. ", Example 1, 100) If x<1000 Then MsgBox "Your number is smaller than 1000." Elseif x<2000 Then MsgBox "Your number is smaller than 2000." Elseif x<3000 Then MsgBox "Your number is smaller than 3000." Elseif x<4000 Then MsgBox "Your number is smaller than 4000." Else MsgBox "Your number is greater than or equal to 4000." End If