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
- Else
- MsgBox i & " is greater than " & j
- End If
- End Sub
Here is the script from the editor
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