Vba
Excel VBA Function Tutorial: Return, Call, Examples
What is a Function? A function is a piece of code that performs a specific task and returns a...
These are operators that are used to compare values. Comparison operators include equal to, less than, greater than and not equal to
Comparison operators are used to compare values for validation purposes. Let's say you are developing a simple point of sale application. In this application, you want to validate the values entered before you post. In such cases, you can use comparison operators. This operator will check against the negative numbers or to ensure that the amount paid does not exceed the billed amount. Comparison operators come in handy in such situations.
The following table lists the comparison operators defined in VBA.
| Operator | Description |
|---|---|
| = | Equal: checks if two values are equal. It is also used as an assignment operator |
| < | Less than: This operator is used to subtract numbers |
| > | Greater than: This operator is used to multiply numbers |
| <> | Not equal to: This operator is used to divide numbers |
| <= | Less than or equal to: |
| >= | Greater than or equal to: |
The following table shows Excel VBA Comparison Operators with examples and output.
| S/N | Operator | Example | Output |
|---|---|---|---|
| 1 | = | If x = z Then | Returns true if they are equal, else it returns false |
| 2 | < | If x < z Then | Returns true if x is less than z, else it returns false |
| 3 | > | If x > z Then | Returns true if x is greater than z, else it returns false |
| 4 | <> | If x <> z Then | Returns true if they are not equal, else it returns false |
| 5 | <= | If x <= z Then | Returns true if x is less than or equal to z, else it returns false |
| 6 | >= | If x >= Then | Returns true if x is greater than z, else it returns false |
Equal Comparison Operator
If 2 = 1 Then
MsgBox "True", vbOKOnly, "Equal Operator"
Else
MsgBox "False", vbOKOnly, "Equal Operator"
End If
HERE,
Executing the above code gives the following results
What is a Function? A function is a piece of code that performs a specific task and returns a...
VBA String Operators String data is used to hold data that is made up of numbers, characters, and...
What is an Excel Macro? Excel Macro is a record and playback tool that simply records your Excel...
VBA Logical Operators: AND, OR, NOT Excel VBA Logical Operators Let's say you want to process a...
Download PDF Following are frequently asked questions in interviews for freshers as well...
What is VBA Array? An array is defined as a memory location capable of storing more than one...