lafata2000
New Member
- Joined
- Sep 29, 2021
- Messages
- 4
- Office Version
- 365
- Platform
- 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
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.
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
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 1 | Column 2 | Column 2 | Results | |
ABSBR KIT | RS5000X SHOCK | SHOCK ABSORBER | SHOCK |
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 1 | Column 2 | Column 2 | Results | |
ABSBR KIT | RS5000X SHOCK | SHOCK 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