Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://excel-egy.com/forum/t4091
- ---------------------------------
- Sub Compare_Two_Strings_Get_Difference_By_UDF()
- Dim a, i As Long
- With Sheet1
- a = .Range("C2:E" & .Cells(Rows.Count, 3).End(xlUp).Row).Value
- For i = LBound(a) To UBound(a)
- a(i, 3) = Difference(CStr(a(i, 1)), CStr(a(i, 2)), " - ")
- Next i
- .Range("C2").Resize(UBound(a, 1), UBound(a, 2)).Value = a
- End With
- End Sub
- Function Difference(txt1 As String, txt2 As String, Optional delim As String = ", ") As String
- Dim x, y, f As Boolean, s As String, i As Long, j As Long
- If InStr(txt1, delim) > 0 And InStr(txt2, delim) > 0 Then
- x = Split(txt1, delim)
- y = Split(txt2, delim)
- For i = LBound(x) To UBound(x)
- f = False
- For j = LBound(y) To UBound(y)
- If x(i) = y(j) Then f = True
- Next j
- If Not f Then s = s & IIf(s = "", "", delim) & x(i)
- Next i
- For j = LBound(y) To UBound(y)
- f = False
- For i = LBound(x) To UBound(x)
- If y(j) = x(i) Then f = True
- Next i
- If Not f Then s = s & IIf(s = "", "", delim) & y(j)
- Next j
- End If
- Difference = s
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement