VBA StrComp Function: The StrComp function in VBA compares two strings and returns an integer value displaying the result of the comparison.

Syntax

Parameter

String1 (required)– This parameter represents the first string to be compared.

String2 (required) – This parameter represents the second the second string to be compared.

Compare (optional) – This parameter represents the type of comparison to make. The default value is vbBinaryCompare.

It can take any of the following values:

  • vbBinaryCompare (default value): To perform a binary comparison
  • vbTextCompare: To perform a text comparison
  • vbDatabaseCompare: To perform a database comparison

Return

This function integer value displaying the result of the comparison. The returned output can be of any of the following values:

  • It returns 0, if both the strings are equal.
  • It returns -1, if String1 is less than String2
  • It returns 1, if String1 is greater than String2.
  • It returns null, if both the strings are Null

Example 1

Output

Both the strings are equal!

VBA StrComp Function

Example 2

Output

VBA StrComp Function
VBA StrComp Function
VBA StrComp Function
VBA StrComp Function

Pin It on Pinterest

Share This