Find Common Text in 3 Rows: VBA

lafata2000

New Member
Joined
Sep 29, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,

I have the below VBA code; however, I need it edited a bit and need some help!!!

Current Results: The code is taking the most frequent text from all 3 columns as a whole
Column 1Column 2Column 2Results
ABSBR KITRS5000X SHOCKSHOCK ABSORBERSHOCK

Needed Results: The code to take the most frequent text from all 3 columns together and show results as blank if there is no match.
Column 1Column 2Column 2Results
ABSBR KITRS5000X SHOCKSHOCK ABSORBER

Sub jec()

Dim dict As Object
Dim jv, ar, sp, it As Variant
Dim i As Long
Dim c00 As String

Set dict = CreateObject("scripting.dictionary")
dict.CompareMode = 1
jv = Sheets(1).Cells(1, 1).CurrentRegion.Resize(, 5)

For i = 2 To UBound(jv)
ar = Split(Replace(Join(Array(jv(i, 1), jv(i, 2), jv(i, 3))), ",,", " "))
With Cells(1, 100).Resize(UBound(ar) + 1)
.ClearContents
.Value = Application.Transpose(ar)
sp = Filter(Application.Transpose(Evaluate(Replace("if(max(countif(@@,@@))=countif(@@,@@),@@,""~"")", "@@", .Address))), "~", False)
End With

For Each it In sp
c00 = dict(it)
Next

jv(i, 5) = Join(dict.keys, ", ")
dict.RemoveAll
Next

Sheets(1).Cells(1, 1).CurrentRegion.Resize(, 5) = jv
End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi, according to your 'attachment' a VBA demonstration for starters :​
VBA Code:
Sub Demo1()
    Dim V, S$(), R&, W
        V = [A1].CurrentRegion.Value2:  If UBound(V) = 1 Then Beep: Exit Sub
        ReDim S(2 To UBound(V), 0)
    With Application
    For R = 2 To UBound(V)
        V(R, 2) = Split(V(R, 2)):  V(R, 3) = Split(V(R, 3))
    For Each W In Split(V(R, 1))
        If IsNumeric(.Match(W, V(R, 2), 0)) And IsNumeric(.Match(W, V(R, 3), 0)) Then S(R, 0) = S(R, 0) & W & " "
    Next W, R
    End With
        [E2].Resize(R - 2).Value2 = S
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,052
Messages
6,122,878
Members
449,097
Latest member
dbomb1414

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