Notifications
Clear all

Apagar linhas duplicadas, ordenadas

2 Posts
2 Usuários
0 Reactions
920 Visualizações
(@adhuters)
Posts: 0
New Member
Topic starter
 

Galera,

Preciso de ajuda, preciso excluir linhas duplicadas, porém, quero apagar de cima para baixo.

Por exemplo, tenho a linha 1,2,3 e 94,95,96 que são linhas duplicadas, gostaria de apagar a linha 1,2,3 e manter a 94,95,96.

Agradeço pela ajuda!

 
Postado : 30/04/2018 3:23 am
(@klarc28)
Posts: 0
New Member
 

https://www.youtube.com/results?search_query=vba+remover+duplicatas

Private Sub ComboBox1_Enter()
    

    
End Sub


Private Sub UserForm_Initialize()
    linha = 2
    Do While Plan1.Cells(linha, 1) <> ""
        linha = linha + 1
    Loop
    Fim = linha - 1
    
    With Plan1
        
        For linha = 2 To Fim
            'A linha abaixo verifica se tem repetição de dados, para não duplicar ao carregar o Combobox
            Registro = WorksheetFunction.CountIf(Range(Cells(1, 1), Cells(linha, 1)), Cells(linha, 1))
            If Registro = 1 Then
                
                ComboBox1.AddItem .Cells(linha, 1)
                
            End If
        Next linha
    End With
    
    
    '//////NÃO ESTOU CONSEGUINDO UNIR O CÓDIGO ACIMA A ESSE\\\\\\
    
    'Dim Ray, i As Integer, j As Integer, temp As String
    'With ComboBox1
    'Ray = Application.Transpose(.List)
    'For i = 1 To UBound(Ray) - 1
    'For j = i To UBound(Ray)
    'If Ray(j) < Ray(i) Then
    'temp = Ray(i)
    'Ray(i) = Ray(j)
    'Ray(j) = temp
    'End If
    'Next j
    'Next i
    '.List = Ray
    'End With
    
    
    Dim I As Long
    Dim J As Long
    Dim ANTERIOR As String
    Dim POSTERIOR As String
    
    If ComboBox1.ListCount >= 1 Then
        For I = 0 To ComboBox1.ListCount - 2
            For J = I + 1 To ComboBox1.ListCount - 1
                
                ANTERIOR = ComboBox1.List(I)
                POSTERIOR = ComboBox1.List(J)
                
                If ANTERIOR > POSTERIOR Then
                    
                    ANTERIOR = ComboBox1.List(J)
                    POSTERIOR = ComboBox1.List(I)
                    
                    ComboBox1.List(I) = ANTERIOR
                    ComboBox1.List(J) = POSTERIOR
                End If
                
            Next J
            
        Next I
        
    End If
End Sub
 
Postado : 30/04/2018 3:54 am