How to search for random patterns within a column

Frustrated_excel274

New Member
Joined
Feb 12, 2022
Messages
3
Office Version
  1. 2010
Platform
  1. Windows
Hi All, I'm totally lost and have been searching for 2 days on how to do this. I have an excel spreadsheet of with each cell containing random numbers and letters. I want do a search that will compare the cells and automatically find any 5 character patterns. Case sensitivity doesn't matter. Example:
A1: FeexV6bAHb8ybZjq
A2: iVkebCz8JfEEXvgkPiM
A3: hg363dRjUgq2feExvXL

I would want a search function that would output "feexv" because it is the most common 5 character set found. Is there a way to do this?
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Are you trying to do this with VBA or straight formulas? Is this a one-time analysis or will the list of random text strings constantly be changing? If you are trying to do it with formulas, I think I came up with a solution. See this file & let me know if it does the trick. Just put the random text strings in A2:A4 and the spreadsheet should do the rest. You can insert additional rows above row 4 to add more text strings and just fill down the formulas is columns D:S from row 2. But if you add rows to the input range, you are probably going to need to make the "Unique Blobs" range really long though (this is an array formula, needs to be cntl-shift-enter). Probably cleaner to do this in VBA if the large data set is large.

Proposed Solution: https://file.io/6B81wYF1kWXa
 
Upvote 0
It's a one-time analysis and the data set is large. I was trying to do it with a formula but couldn't get it work. I'm not sure what a VBA is. I'm willing to try anything to make it work. I tried clicking on your link but it says the file is deleted and nothing else.
 
Upvote 0
how big is your data ? How many cells * average number of characters within a cell
Can you add some cells with the XL2BB-tool ?
Still excel2010 ?
 
Upvote 0
how big is your data ? How many cells * average number of characters within a cell
Can you add some cells with the XL2BB-tool ?
Still excel2010 ?
Still using excel 2010 but I've also got access to Google docs. It's a large document. Thousands of cells but all in the same column. All cells have 34 characters.
 
Upvote 0
@gurs
In relation to your style of answer in post #2 above, please review #4 of the Forum Rules

@Frustrated_excel274
Give the following macro a try with a copy of your workbook.
It assumes the values are in column A and puts the result(s) in column B.
My data may not be representative of yours but processed 12,000 rows in less than half a second.

To implement ..
1. With your workbook active press Alt+F11 to bring up the vba window.
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Press Alt+F8 to bring up the Macro dialog
6. Select the macro & click ‘Run’
7. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

VBA Code:
Sub Common5()
  Dim d As Object
  Dim a As Variant, itm As Variant, b As Variant
  Dim s As String, ss As String
  Dim i As Long, j As Long, k As Long, maxx As Long
 
  Set d = CreateObject("Scripting.Dictionary")
  d.CompareMode = 1
  a = Range("A1", Range("A" & Rows.Count).End(xlUp)).Value
  ReDim b(1 To UBound(a) * 30, 1 To 1)
  For i = 1 To UBound(a)
    s = a(i, 1)
    For j = 1 To Len(s) - 4
      ss = LCase(Mid(s, j, 5))
      d(ss) = d(ss) + 1
      If d(ss) > maxx Then maxx = d(ss)
    Next j
  Next i
  For Each itm In d.Keys
    If d(itm) = maxx Then
      k = k + 1
      b(k, 1) = itm
    End If
  Next itm
  Range("B1").Resize(k).Value = b
End Sub

Here is my small sample data and results.

Frustrated_excel274.xlsm
AB
1FeexV6bAHb8ybZjqfeexv
2iVkebCz8JfEEXvgkPiM63drj
3hg363dRjUgq2feExvXL
4hk363dRjkgq2fzExjXL
5hzz63dRjagq2feExjXL
6
Sheet1
 
Upvote 0
@gurs
I have removed your last post. Please see the start of post #6 for the reason.
 
Upvote 0
Variant on Peter_SSs in #6 with all the collected substrings
VBA Code:
Sub Common5bis()
     Dim Joined
     Set d = CreateObject("Scripting.Dictionary")               'make dictionary
     d.CompareMode = 1                                          'not case sensitive
     a = Range("A1", Range("A" & Rows.Count).End(xlUp)).Value   'data to array
     For i = 1 To UBound(a)                                     'loop trough alle records
          If Len(a(i, 1)) >= 5 Then                             'length at least 5
               For l = 1 To Len(a(i, 1)) - 4                    'all strings withing record
                    s = Mid(a(i, 1), l, 5)                      'that string
                    d(s) = d(s) + 1                             'increment
               Next
          End If
     Next

     Joined = Application.Index(Array(d.Keys, d.items), 0, 0)   'join the keys and the items
     With Range("D1").Resize(UBound(Joined, 2), 2)              'export range
          .EntireColumn.ClearContents                           'clear previous
          .Value = Application.Transpose(Joined)                'write to sheet
          .Sort .Range("B1"), xlDescending, Header:=xlNo        'sort descending
     End With

End Sub
Map1
ABCDE
1FeexV6bAHb8ybZjqfeexvFeexV3
2iVkebCz8JfEEXvgkPiM63drj63dRj3
3hg363dRjUgq2feExvXL363dR2
4hk363dRjkgq2fzExjXLgq2fe2
5hzz63dRjagq2feExjXLq2feE2
62feEx2
7ExjXL2
8eexV61
9exV6b1
10xV6bA1
11V6bAH1
126bAHb1
13bAHb81
14AHb8y1
15Hb8yb1
16b8ybZ1
178ybZj1
18ybZjq1
19iVkeb1
20VkebC1
21kebCz1
22ebCz81
23bCz8J1
24Cz8Jf1
25z8JfE1
268JfEE1
27JfEEX1
Blad1
 
Upvote 0
@gurs
I have removed your last post. Please see the start of post #6 for the reason.
Well that's a bummer. I have a perfectly functional solution, with absolutely no code, VBA, trusted locations or XLSM required. I would be happy to post the XLSX file to this thread but it won't allow it. Not sure why this forum would want to prevent me from sharing my solution with the OP. Seems against the spirit of the forum, which I thought was to allow users to help other users. Sorry, @Frustrated_excel274, I tried!
 
Upvote 0
@gurs
I have removed your last post. Please see the start of post #6 for the reason.
The OP actually said "I don't know what a VBA is". Pretty clear a no-code solution is the optimal path here. Frustrating that I developed one but am prevented from sharing it.
 
Upvote 0

Forum statistics

Threads
1,215,020
Messages
6,122,709
Members
449,093
Latest member
Mnur

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