Vba if then else, condition in Excel

No script can be used a achieve a requirement without checking various conditions that must be satisfied.

Excel offers "If Then..Else " for this very purpose.

This statement helps execute a script or part of it based on certain conditions.

Example: Check if a number is graeter than or smaller than the other and execute corresponding code

  1. Sub If_then_demo()
  2. Dim i, j As Integer
  3. i = 2
  4. j = 4
  5. If i < j Then
  6. MsgBox i & " is less than " & j
  7. Else
  8. MsgBox i & " is greater than " & j
  9. End If
  10. End Sub

Here is the script from the editor

excel vba if then else, condition

excel vba if then else, condition

Here is the Result

 

You can find similar Excel Questions and Answer hereunder

1) How can I find the count of records that meet multiple conditions in my raw data table?

2) Formula does not calculate in Excel

3) How do I have proper (Capitalize the first letter in each word of a text) text in cells ?

4) How to control forms in Excel VBA

5) How do you know which column was used last, Here the explanation to find it with VBA

6) How can I get input from user through a prompt and assign user's input to a cell?

7) I conducted a test and the test scores are available - how can I get Percentile rank of students?

8) I am a construction Engineer. Considering a room with dimension, 14ft x 12ft can I find the side of the largest square tile which can tile the room?

9) How can I add a 3 Month Moving average Trend line to my line chart?

10) How to enable or disable macros execution or loading in Excel

 

Here the previous and next chapter