I need help to read mismatch string between two cells it may custom UDF (User Defined Function) or Macro to find.
For Ex. Input is A1 = C1,C2,C3,C5 and B1=C1,C4,C2
Expected O/P is C1 = C3,C5,C4
Regards,
Venkateswaran K
I need help to read mismatch string between two cells it may custom UDF (User Defined Function) or Macro to find.
For Ex. Input is A1 = C1,C2,C3,C5 and B1=C1,C4,C2
Expected O/P is C1 = C3,C5,C4
Regards,
Venkateswaran K
Here's the UDF for you:
Put it into a standard module (Insert > Module), then use in a cell like so:![]()
Option Explicit Function CompareLists(Rng1 As Range, Rng2 As Range, Optional Delim As String) As String Dim Arr As Variant, buf As String, n As Long If Delim = "" Then Delim = "," Arr = Split(Rng1.Cells(1), Delim) For n = LBound(Arr) To UBound(Arr) If InStr(Rng2, Arr(n)) = 0 And Len(Arr(n)) > 0 Then buf = buf & "," & Arr(n) Next n Arr = Split(Rng2.Cells(1), Delim) For n = LBound(Arr) To UBound(Arr) If InStr(Rng1, Arr(n)) = 0 And Len(Arr(n)) > 0 Then buf = buf & "," & Arr(n) Next n If Len(buf) > 0 Then CompareLists = Mid(buf, 2, Len(buf)) Else CompareLists = "All match" End Function
=CompareLists(A1, B1, ",")
You can use any delimiter you want in the 3rd paramater, if you leave it out it will default to comma.
Last edited by JBeaucaire; 09-29-2012 at 12:15 PM.
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
?None of us is as good as all of us? - Ray Kroc
?Actually, I *am* a rocket scientist.? - JB (little ones count!)
ExcellentThanks its solved my problem.
Regards,
Venkateswaran K
MODERATOR'S NOTE: Please do not quote entire posts into your posts. Thanks.
Last edited by JBeaucaire; 09-29-2012 at 02:11 PM. Reason: Removed unnecessary whole-post quotation.
don't ask me comments, it's not mine![]()
Function GetDiff(txt1 As String, txt2 As String) As String Dim e, a(1 To 3) As String Static dic As Object If dic Is Nothing Then Set dic = CreateObject("Scripting.Dictionary") dic.CompareMode = 1 dic.RemoveAll For Each e In Split(txt1, ",") If Trim$(e) <> "" Then dic(Trim$(e)) = Empty End If Next For Each e In Split(txt2, ",") If Trim$(e) <> "" Then If dic.exists(Trim$(e)) Then a(2) = a(2) & IIf(a(2) = "", "", ", ") & Trim$(e) dic.Remove Trim$(e) Else a(3) = a(3) & IIf(a(3) = "", "", ", ") & Trim$(e) End If End If Next a(1) = Join$(dic.keys, ", ") & ", " & a(3) GetDiff = a(1) End Function
Last edited by patel45; 09-29-2012 at 12:21 PM.
If solved remember to mark Thread as solved
I have marked this thread solved for you.
In the future please select Thread Tools from the menu above and mark the thread as solved. Thanks.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks