Formula to compare various cells in a row and give result if it is common in multiple cells

bb19august

New Member
Joined
Feb 1, 2019
Messages
18
Dear All,
Need help with a excel formula to compare various cells in a row and give result if it is common data in multiple cells

Condition:
- if the cells have a common alphanumeric in a row, at least two or above, then print it as result else "No Result"

- different alphanumeric can be separated by commas also in the cells

- If there are two alphanumeric, common in the cells then the result to be separated by comma

- if there are no data (blank) in the cells then result is "No result"

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Car[/TD]
[TD]Bus[/TD]
[TD]Train[/TD]
[TD]Result[/TD]
[/TR]
[TR]
[TD]F1, F2, F3[/TD]
[TD]F1[/TD]
[TD]F1[/TD]
[TD]F1[/TD]
[/TR]
[TR]
[TD]F1, F2, F3[/TD]
[TD]F1, F2, F4[/TD]
[TD]F2, F5, F6[/TD]
[TD]F1, F2[/TD]
[/TR]
[TR]
[TD]F1, R1[/TD]
[TD]R2[/TD]
[TD]F3, F4, R7[/TD]
[TD]No Result[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]R1[/TD]
[TD]No Result[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Re: Need help with a excel formula to compare various cells in a row and give result if it is common in multiple cells

Here's a UDF you can try. Use it like a native Excel worksheet function as in the example below.
Excel Workbook
ABCD
1CarBusTrainResult
2F1, F2, F3F1F1F1
3F1, F2, F3F1, F2, F4F2, F5, F6F1, F2
4F1, R1R2F3, F4, R7No Result
5R1No Result
6No Result
Sheet2


Code:
Function GetRepeaters(R As Range) As String
Dim d As Object, x As Variant, i As Long, S As String, Out As String
Set d = CreateObject("Scripting.Dictionary")
S = Join(Application.Index(R.Value, 1, 0), ", ")
x = Split(S, ", ")
For i = LBound(x) To UBound(x)
    If d.exists(x(i)) And InStr(Out, x(i)) = 0 Then
        Out = Out & ", " & x(i)
    ElseIf Not d.exists(x(i)) Then
        d.Add x(i), d.Count
    End If
Next i
If Mid(Out, 3) = "" Then
    GetRepeaters = "No Result"
Else
    GetRepeaters = Mid(Out, 3)
End If
End Function
 
Upvote 0
Re: Need help with a excel formula to compare various cells in a row and give result if it is common in multiple cells

You are still young :) Result as expected. Thank you so much for your time and help.
 
Upvote 0
Re: Need help with a excel formula to compare various cells in a row and give result if it is common in multiple cells

You are still young :) Result as expected. Thank you so much for your time and help.
You are welcome - thanks for the reply.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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