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
- Sub If_then_demo()
- Dim i, j As Integer
- i = 2
- j = 4
- If i < j Then
- MsgBox i & " is less than " & j
- MsgBox i & " is greater than " & j
- End If
- End Sub
Here is the script from the editor
Here is the Result