Excel StrComp Function: Compare String Values For Matches
Có thể bạn quan tâm
StrComp Excel function is a helpful function to use when comparing strings values to identify matches.
The Basics:
StrComp ( StringA, StringB, Compare Option)
StringA & StringB = The two strings we want to compare
Compare Option = What compare option we want to use. We can use this option when we want to make sure our string compare is case sensitive or not.
Now let’s look at an example. For this example, we have two columns of data we want to compare to see if they are the same.
Code
Dim A As Long ’The counter we will be using the process our records
Dim StringA, StringB As String ‘Strings to compare
Dim Position As Long ’This variable will contain the position of the character searched for
For A = 2 To 4
StringA = ActiveSheet.Cells(A, 1).Value ‘Assigns the value to the first string to compare
StringB = ActiveSheet.Cells(A, 2).Value ‘Assigns the value to the first string to compare
ActiveSheet.Cells(A, 3).Value = StrComp(StringA, StringB, vbTextCompare)
Next
trim function where needed.
Output
A match would have a results value of 0. If the values do not match an -1 is returned in Excel.
Do you want to learn more about Excel and become a PRO in VBA at your own pace? Our friends over at Excel Campus will teach you everything you need to know!
Từ khóa » Visual Basic Excel Compare Cell Values
-
Compare 2 Cells In Excel By Using Vba - Stack Overflow
-
Vba -excel -how To Check And Compare Cell Value Against Next Cell's ...
-
Compare Ranges In Excel VBA (In Easy Steps)
-
VBA Cell Value - Get, Set, Or Change - Automate Excel
-
Comparing Two Cells With VBA | MrExcel Message Board
-
Excel Macro To Compare Two Columns (4 Easy Ways)
-
Compare Cells With This Excel VBA Function
-
How To Compare Cells With VBA - YouTube
-
How To Compare The Values Of Cells In A Range Against One ... - Quora
-
How To Compare Two Columns In Excel Using VBA - SpreadsheetWeb
-
Use VBA To Compare Two Ranges In Excel And Highlight The Cells ...
-
Get Cell Value In Excel VBA - WallStreetMojo
-
By Using VBA How Do I Compare Values - Super User
-
VBA Comparison Operators: Not Equal, Less Than Or Equal To - Guru99