separate pairs without repetition of digits.

piter

Active Member
Joined
Jul 22, 2011
Messages
316
Office Version
  1. 2016
Platform
  1. Windows
pares separados sem repetição de dígitos. exemplo
01 62 = sim
01 60, ou 12 17, etc. nao por possuir dígitos repetidos de 0 a 9, tanto inicial quanto final do par, objetivo é separar os pares sem repetição de dígitos da lista azul
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
From Google Translator:
separate pairs without repeating digits. example
01 62 = yes
01 60, or 12 17, etc. not because it has repeated digits from 0 to 9, both initial and final of the pair, the objective is to separate pairs without repeating digits from the blue list
Try:
VBA Code:
Sub ConcatAndCheckRange()
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Sheets("Sheet1") ' Change "Sheet1" to your sheet name
   
    Dim lastRow As Long
    Dim i As Long
    Dim strA As String
    Dim strB As String
    Dim concatenatedStr As String
    Dim hasRepeats As Boolean
    Dim j As Long, k As Long

    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
   
    ' Loop through each row in the range
    For i = 1 To lastRow
        strA = CStr(ws.Cells(i, 1).Value)
        strB = CStr(ws.Cells(i, 2).Value)
        concatenatedStr = strA & strB
       
        ' Check for repeated characters
        hasRepeats = False
        For j = 1 To Len(concatenatedStr) - 1
            For k = j + 1 To Len(concatenatedStr)
                If Mid(concatenatedStr, j, 1) = Mid(concatenatedStr, k, 1) Then
                    hasRepeats = True
                    Exit For
                End If
            Next k
            If hasRepeats Then Exit For
        Next j

        If Not hasRepeats Then
            ws.Cells(i, 3).Value = strA
            ws.Cells(i, 4).Value = strB
        End If
    Next i
End Sub
 
Upvote 0
try
Code:
Sub tes()
    Dim a, i&, s$, f$
    With Range("a4", Range("a" & Rows.Count).End(xlUp)).Resize(, 2)
        f = .Cells(1).NumberFormatLocal
        a = .Value
    End With
    With CreateObject("VBScript.RegExp")
        .Pattern = "^.*(\d).*\1.*"
        For i = 1 To UBound(a, 1)
            s = Format$(a(i, 1), f) & Format$(a(i, 2), f)
            If .test(s) Then a(i, 1) = "": a(i, 2) = ""
        Next
    End With
    With [d4].Resize(UBound(a, 1), 2)
        .NumberFormatLocal = f
        .Value = a
    End With
End Sub
 
Upvote 0
hello ,Cubist and Fuji, correct , comglatulations, thank you!
 
Upvote 0

Forum statistics

Threads
1,223,924
Messages
6,175,415
Members
452,640
Latest member
steveridge

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