If cell contains string of letter or number repetition vba

borgercity

New Member
Joined
May 18, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi,
I need a formula which makes it possible to find string of letter or number repetition in a specific colomn such as:
- ‘XXXXXX’ or ‘ABCDEF’
- ‘123456’ or ‘111111’

Thank you in advance!
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Something like this?

Excel Formula:
=IF((IFERROR(FIND("XXXXXX",A5),0)+IFERROR(FIND("ABCDEF",A5),0)+IFERROR(FIND("123456",A5),0)+IFERROR(FIND("111111",A5),0))>0,TRUE,FALSE)
 
Upvote 0
Something like this?

Excel Formula:
=IF((IFERROR(FIND("XXXXXX",A5),0)+IFERROR(FIND("ABCDEF",A5),0)+IFERROR(FIND("123456",A5),0)+IFERROR(FIND("111111",A5),0))>0,TRUE,FALSE)
Thanks but that's not what I'm looking. The list is non-exhaustive. Those I have mentioned are just a few examples :) I don't know if it's possible to have something in VBA for that matter
 
Upvote 0
I think you may need to explain in more detail.
I can see how "XXXXXX" or "111111" is repetition, but how are you considering "ABCDEF" or "123456" repetition?

Also, how long are these strings, and how many consecutive characters do you need for it to be considered?
What if you have things like?
"AAACKS" or "111156"?

I also have a feeling that you may be oversimplifying your examples.
Can you show us a much larger data set that is actually representative of your real data, and then show us your expected results from that data (you also haven't told us what you want to do with this data when found)?
 
Upvote 0
I think you may need to explain in more detail.
I can see how "XXXXXX" or "111111" is repetition, but how are you considering "ABCDEF" or "123456" repetition?

Also, how long are these strings, and how many consecutive characters do you need for it to be considered?
What if you have things like?
"AAACKS" or "111156"?

I also have a feeling that you may be oversimplifying your examples.
Can you show us a much larger data set that is actually representative of your real data, and then show us your expected results from that data (you also haven't told us what you want to do with this data when found)?
I apologize for my unclear explanation. It concerns a list of customers that I cannot simply place here. Suppose column A contains all the names of the customers. Then the intention is to check whether the information is not unclear. Unclear means, among other things, repetition of letters and numbers. Suppose a customer passes on "AABC" as his name, and in the case of the character of 2 successive repetitions, this should give an indication for further checking (let us forget "12345" and "ACBDE").
 
Upvote 0
So, you are just trying to look for patterns that do not look like names?
If so, looking for numbers or symbols is simple enough, but letter patterns can get a lot trickier, because how can you tell what is a name and what isn't?
A bunch of names have repeating letters, i.e.
Aaron
Miller
Reed
 
Upvote 0
Is it possible to tackle this a different way and start with a "definitive" approved customer list? It would then be a matter of comparing your table against the control list and approving all new approved entries as a one off task, by adding them to said control list.
 
Upvote 0
in the case of the character of 2 successive repetitions, this should give an indication for further checking
If that is in fact what you want, then you could try this macro.

VBA Code:
Sub RepeatLetters()
  Dim RX As Object
  Dim a As Variant, b As Variant
  Dim i As Long
  
  Set RX = CreateObject("VBScript.RegExp")
  RX.Global = True
  RX.IgnoreCase = True
  RX.Pattern = "(.)(?=\1)"
  With Range("A1", Range("A" & Rows.Count).End(xlUp))
    a = .Value
    ReDim b(1 To UBound(a), 1 To 1)
    b(1, 1) = "Repeat Characters"
    For i = 2 To UBound(a)
      If RX.Test(a(i, 1)) Then b(i, 1) = RX.Execute(a(i, 1)).Count
    Next i
    .Offset(, 1).Value = b
  End With
End Sub

My sample data and results.
This code checks for any repeat characters, not just letters. For example, there are no repeat letters in row 10 but there is a double space between the two names.

borgercity.xlsm
AB
1NamesRepeat Characters
2AABC1
3Jones
4Jjones1
5
6Peters
7Reed1
8Llewwellyn3
9AAABC2
10Ken Smith1
Sheet1


If you wanted a version without using regular expressions (perhaps it needs to also work on a Mac) then this produces the same results.

VBA Code:
Sub RepeatLettersB()
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long, k As Long
  Dim s As String
  
  With Range("A1", Range("A" & Rows.Count).End(xlUp))
    a = .Value
    ReDim b(1 To UBound(a), 1 To 1)
    b(1, 1) = "Repeat Characters"
    For i = 2 To UBound(a)
      s = LCase(a(i, 1))
      k = 0
      For j = 2 To Len(s)
        If Mid(s, j, 1) = Mid(s, j - 1, 1) Then k = k + 1
      Next j
      If k > 0 Then b(i, 1) = k
    Next i
    .Offset(, 1).Value = b
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,954
Messages
6,122,462
Members
449,085
Latest member
ExcelError

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