Oct 30 2020 03:12 AM
What formula will help me write common numbers from 2 cells? In cell A1 I have: 1,2,3. In cell B1 I have: 2,3,4. I would like cell C1 to write to me: 2 and 3.
Oct 30 2020 04:41 AM
Here is a custom VBA function:
Function Common(ByVal s1 As String, ByVal s2 As String) As String
Dim a() As String
Dim i As Long
Dim r As String
s1 = Replace(s1, " ", "")
s2 = "," & Replace(s2, " ", "") & ","
a = Split(s1, ",")
For i = 0 To UBound(a)
If InStr(s2, "," & a(i) & ",") Then
r = r & "," & a(i)
End If
Next i
If r <> "" Then
Common = Mid(r, 2)
End If
End Function
Use like this:
=Common(A1,B1)
Oct 30 2020 10:34 AM - edited Oct 30 2020 10:38 AM
@Grosso1280 alternatively this formula should work (but it does return a blank because I reference the entire column instead of only the data set range):
=IFERROR(SORT(INDEX(B:B,UNIQUE(MATCH(A:A,B:B,0)))),"")
Oct 30 2020 02:07 PM
With formula that could be
=TEXTJOIN(",",1,
XLOOKUP(
FILTERXML("<r><n>" & SUBSTITUTE(A1,",","</n><n>") & "</n></r>", "//n"),
FILTERXML("<r><n>" & SUBSTITUTE(B1,",","</n><n>") & "</n></r>", "//n"),
FILTERXML("<r><n>" & SUBSTITUTE(B1,",","</n><n>") & "</n></r>", "//n"),
""))