# Thread: How to compare text string of two different columns in Excel

1. Member
Join Date
Dec 2011
Posts
64

## How to compare text string of two different columns in Excel

Hi friends recently I am trying to make the macros in Excel so that I compare the two different texts String Present in two different cells of two different columns in Excel, but however I am not able to create such tough macros or formula that I can make use. So if you guys have any ideas then please let me know.

2. Member
Join Date
May 2011
Posts
526

## Re: How to compare text string of two different columns in Excel

Try this logic may it help you to make the comparison of two different Text string in Excel
Dim TopMatch As Integer
Dim strCompare As String
Function Fuzzy(strIn1 As String, strIn2 As String) As Single
Dim L1 As Integer
Dim In1Mask(1 To 24) As Long 'strIn1 is 24 characters max
Dim iCh As Integer
Dim N As Long
Dim strTry As String
Dim strTest As String

TopMatch = 0
L1 = Len(strIn1)
strTest = UCase(strIn1)
strCompare = UCase(strIn2)

For iCh = 1 To L1
Next iCh

For N = 2 ^ (L1 + 1) - 1 To 1 Step -1
strTry = ""
For iCh = 1 To L1
strTry = strTry & Mid(strTest, iCh, 1)
End If
Next iCh
If Len(strTry) > TopMatch Then TestString strTry
Next N
Fuzzy = TopMatch / CSng(L1)
End Function
And this sub procedure

Sub TestString(strIn As String)
Dim L As Integer
Dim strTry As String
Dim iCh As Integer
L = Len(strIn)
If L <= TopMatch Then Exit Sub

strTry = "*"

For iCh = 1 To L
strTry = strTry & Mid(strIn, iCh, 1) & "*"
Next iCh

If strCompare Like strTry Then
If L > TopMatch Then TopMatch = L
End If
End Sub

3. Member
Join Date
May 2011
Posts
410

## Re: How to compare text string of two different columns in Excel

Even I was also confused and make the several attempts for creating these Programs but finally I have created a function that will work for this query.
Function FrstLtrs(str As String) As String

Dim temp
Dim i As Long
temp = Split(Trim(str))
For i = 0 To UBound(temp)
FrstLtrs = FrstLtrs & Left(temp(i), 1)
Next i
Max

4. Member
Join Date
Jun 2011
Posts
804

## Re: How to compare text string of two different columns in Excel

The above works but there is need to make some changes that you have to modify
Function FrstLtrs(str As String) As String
Dim temp
Dim i As Long
temp = Split(Trim(str))
For i = 0 To UBound(temp)
FrstLtrs = FrstLtrs & Left(temp(i), 1)
Next i
End Function
May this will be the correct function that works.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•