How to use the STRCOMP Function (VBA)
Description
The Microsoft Excel STRCOMP function returns an integer value representing the result of a string comparison.The STRCOMP function is a built-in function in Excel that is categorized as a String/Text Function. It can be used as a VBA function (VBA) in Excel. As a VBA function, you can use this function in macro code that is entered through the Microsoft Visual Basic Editor.
Syntax
The syntax for the STRCOMP function in Microsoft Excel is:StrComp ( string1, string2 [, compare ] )
Parameters or Arguments
- string1 and string2
- The two strings to compare to each other.
- compare
- 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
Returns
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
- Excel 2016, Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000
Type of Function
- VBA function (VBA)
Example (as VBA Function)
StrComp ("TechOnTheNet.com", "TechOnTheNet.com")
Result: 0
StrComp ("TechOnTheNet.com", "Abc")
Result: 1
StrComp ("TechOnTheNet.com", "Xyz")
Result: -1
StrComp ("TechOnTheNet.com", NULL)
Result: NULL
Dim LResult As Integer
LResult = StrComp ("TechOnTheNet.com", "TechOnTheNet.com")
ليست هناك تعليقات:
إرسال تعليق