This Excel tutorial explains how to use the Excel STRCOMP function with syntax and examples.
compare is optional. This is the type of comparison to perform. The valid choices are:
Let's look at some Excel STRCOMP function examples and explore how to use the STRCOMP function in Excel VBA code:
Description
The Microsoft Excel STRCOMP function returns an integer value representing the result of a string comparison.Syntax
The syntax for the Microsoft Excel STRCOMP function is:StrComp ( string1, string2 [, compare ] )
Parameters or Arguments
string1 and string2 are the two strings to compare to each other.compare is optional. This is the type of comparison to perform. The valid choices are:
VBA Constant | Value | Explanation |
---|---|---|
vbUseCompareOption | -1 | Uses option compare |
vbBinaryCompare | 0 | Binary comparison |
vbTextCompare | 1 | Textual comparison |
Note
- If string1 is equal to string2, the StrComp function will return 0.
- If string1 is less than string2, the StrComp function will return -1.
- If string1 is greater than string2, the StrComp function will return 1.
- If either string1 or string2 is NULL, the StrComp function will return NULL.
Applies To
The STRCOMP function can be used in the following versions of Microsoft Excel:- Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000
Type of Excel Function
The STRCOMP function can be used in Microsoft Excel as the following type of function:- VBA function (VBA)
Example (as VBA Function)
The STRCOMP function can only be used in VBA code in Microsoft Excel.Let's look at some Excel STRCOMP function examples and explore how to use the STRCOMP function in Excel VBA code:
StrComp ("TechOnTheNet.com", "TechOnTheNet.com") Result: 0 StrComp ("TechOnTheNet.com", "Abc") Result: 1 StrComp ("TechOnTheNet.com", "Xyz") Result: -1 StrComp ("TechOnTheNet.com", NULL) Result: NULLFor example:
Dim LResult As Integer LResult = StrComp ("TechOnTheNet.com", "TechOnTheNet.com")