
- VBA Tutorial
- VBA - Home
- VBA - Overview
- VBA - Excel Macros
- VBA - Excel Terms
- VBA - Macro Comments
- VBA - Message Box
- VBA - Input Box
- VBA - Variables
- VBA - Constants
- VBA - Operators
- VBA - Decisions
- VBA - Loops
- VBA - Strings
- VBA - Date and Time
- VBA - Arrays
- VBA - Functions
- VBA - Sub Procedure
- VBA - Events
- VBA - Error Handling
- VBA - Excel Objects
- VBA - Text Files
- VBA - Programming Charts
- VBA - Userforms
- VBA Useful Resources
- VBA - Quick Guide
- VBA - Useful Resources
- VBA - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
VBA - strComp
The StrComp function returns an integer value after comparing the two given strings. It can return any of the three values -1, 0, or 1 based on the input strings to be compared.
- If String 1 < String 2, then StrComp returns -1
- If String 1 = String 2, then StrComp returns 0
- If String 1 > String 2, then StrComp returns 1
Syntax
StrComp(string1,string2[,compare])
Parameter Description
String1 − A required parameter. The first string expression.
String2 − A required parameter. The second string expression.
Compare − An optional parameter. Specifies the string comparison to be used. It can take the following values.
0 = vbBinaryCompare - Performs Binary Comparison(Default)
1 = vbTextCompare - Performs Text Comparison
Example
Add a button and add the following function.
Private Sub Constant_demo_Click() Dim var1 as Variant msgbox("Line 1 :" & StrComp("Microsoft","Microsoft")) msgbox("Line 2 :" &StrComp("Microsoft","MICROSOFT")) msgbox("Line 3 :" &StrComp("Microsoft","MiCrOsOfT")) msgbox("Line 4 :" &StrComp("Microsoft","MiCrOsOfT",1)) msgbox("Line 5 :" &StrComp("Microsoft","MiCrOsOfT",0)) End Sub
When you execute the above function, it produces the following output.
Line 1 :0 Line 2 :1 Line 3 :1 Line 4 :0 Line 5 :1
vba_strings.htm
Advertisements