Comparing character strings in separate cells in Excel spreadsheets?

baigfine23

New Member
Joined
Apr 1, 2014
Messages
1
I am new to Excel VBA or Macro,I have the following Excel problem: Need Macro to do the job
I have a large excel spreadsheet with alpha-numeric data. I want to be able to compare two cells in different row side by side and return the difference in another cell.
e.g. I have in cell B2, "tom, rick, mike, I" and in cell C2, "mike, rick". I need to compare the cell C2 to cell B2 and return the difference in cell D2 which in this case would be the characters " tom, I". They are separated with "," and they can be in different order as you can see in the example.
Thanking you in advance.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Insert a module into the workbook in the VBA editor and add this code. You can then use CSVDIFF as a formula.


Code:
Public Function CSVDIFF(Compare1 As String, Compare2 As String)
Dim arr1
Dim sResult As String
Dim i As Integer
arr1 = Split(Compare1, ",")
For i = LBound(arr1) To UBound(arr1)
    If Not InStr(Compare2, Trim(arr1(i))) > 0 Then
        sResult = sResult & arr1(i) & ","
    End If
Next i
CSVDIFF = Left(sResult, Len(sResult) - 1)
End Function
 
Upvote 0
I am new to Excel VBA or Macro,I have the following Excel problem: Need Macro to do the job
I have a large excel spreadsheet with alpha-numeric data. I want to be able to compare two cells in different row side by side and return the difference in another cell.
e.g. I have in cell B2, "tom, rick, mike, I" and in cell C2, "mike, rick". I need to compare the cell C2 to cell B2 and return the difference in cell D2 which in this case would be the characters " tom, I". They are separated with "," and they can be in different order as you can see in the example.
Thanking you in advance.
Can the two lists have names different from each other and, if so, what should be returned? For example, what if B2 had "Tom,Richard,Harry" and C2 had "Tom,Harry,Bill"... can this happen and, if so, what would you want to see... "Richard,Bill"?

Also, will the two cells always be next to each other like B2 and C2 in your example? If not, what determines he cell to output the difference to?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top