Be the first user to complete this post
|
Add to List |
VBA-Excel: String Functions – strComp()
Description:
The strComp() function compares the two strings and returns the comparison result in numeric form.
Format:
StrComp(string1, string2[, compare])
Arguments:
- String1
- Mandatory
- Type: String
- First string which gets compared with another one
- String2
- Mandatory
- Type: String
- Second string which gets compared with another one
- Compare
- Optional
- Type: Numeric
- The type of comparison to find the string in the main string, like vbBinaryCompare ( Value =0), vbTextCompare (value=1).
OutComes: If String1>String2 Then Result will be 1 Elseif String1<String2 Then Result will be -1 ElseIf String1=String2 Then Result will be 0 End If
Code:
Function FnStrComp(strString1, strString2) intResult = StrComp(strString1, strString2, vbTextCompare) Select Case intResult Case 1: MsgBox strString1 & " string is greater than " & strString2 Case -1: MsgBox strString1 & " string is less than " & strString2 Case 0: MsgBox strString1 & " string is equal to " & strString2 End Select End Function
Example 1:
CallFnStrComp("SUMIT", "sumit")
Example2 :
Call FnStrComp("Sun", "Moon")
Also Read About Other String() Functions
INSTR() | InstrREV() | LCase()
Also Read:
- VBA-Excel : Strings Functions – Instr
- VBA-Excel: Arrays – Multi Dimensional Array
- VBA Excel - Cells, Ranges and Offset : Range
- VBA-Excel: Date-Time Functions – CDate()
- VBA-Excel: Arrays – Two Dimension, Dynamic Array