Notifications
Clear all

Excluir duplicados

13 Posts
2 Usuários
0 Reactions
2,348 Visualizações
(@wenpra)
Posts: 76
Estimable Member
Topic starter
 

Estou com esse código porem eu gostaria que ele desse o loop ate achar todos repetidor no Sheet2, porem o código não esta fazendo isso onde posso estar errando?

Sub DelDups()
Dim iListCount As Integer
Dim iCtr As Integer

Application.ScreenUpdating = False

iListCount = Sheets("Sheet2").Range("A2:A100").Rows.Count

For Each x In Sheets("Sheet1").Range("A2:A10")

For iCtr = 1 To iListCount
If x.Value = Sheets("Sheet2").Cells(iCtr, 1).Value Then
Sheets("Sheet2").Cells(iCtr, 1).Delete xlShiftUp
iCtr = iCtr + 1
End If
Next iCtr
Next
Application.ScreenUpdating = True
End Sub

 
Postado : 16/07/2014 2:32 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa noite!!

Aqui não é local para postagem de dúvidas!!!
Mude a linha a baixo

For Each x In Sheets("Sheet1").Range("A2:A10")

...para

For Each x In Sheets("Sheet2").Range("A2:A10")

Att

 
Postado : 16/07/2014 4:32 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Movi teu tópico para VBA & Macros, pois o local que vc postou é exclusivo para a apresentação dos novos usuários do fórum.

Por enquanto deixei mostrando o tópico nos 2 locais para você se localizar.

Patropi - Moderador

 
Postado : 16/07/2014 5:48 pm
(@wenpra)
Posts: 76
Estimable Member
Topic starter
 

Boa noite!!

Aqui não é local para postagem de dúvidas!!!
Mude a linha a baixo

For Each x In Sheets("Sheet1").Range("A2:A10")

...para

For Each x In Sheets("Sheet2").Range("A2:A10")

Att

Alexandr valeu pela ajuda mas ainda não deu certo na verdade eu tenho Pla1 e Plan2 ele vai pegar o que tenho na plan1 coluna A e excluir todos os repitidos na Plan2 Coluna A esse código ate um certo ponto faz isso, depois ele ta dando a doida e pulando, poderia me ajudar. Exemplo das palnilhas:
Plan1 Plan2
Col.A Col.A
T1-1 T1-1 (Excluir)
T2-2 T1-1 (Excluir)
T2-2 (Excluir)
T2-2 (Excluir)
T3-3
T3-3

Se puder me ajudar agradeço a atenção! Estou tentando usar o código acima mas não esta dando certo! Obrigado....

 
Postado : 17/07/2014 7:12 am
(@wenpra)
Posts: 76
Estimable Member
Topic starter
 

Boa noite!!

Aqui não é local para postagem de dúvidas!!!
Mude a linha a baixo

For Each x In Sheets("Sheet1").Range("A2:A10")

...para

For Each x In Sheets("Sheet2").Range("A2:A10")

Att

Alexandr valeu pela ajuda mas ainda não deu certo na verdade eu tenho Pla1 e Plan2 ele vai pegar o que tenho na plan1 coluna A e excluir todos os repitidos na Plan2 Coluna A esse código ate um certo ponto faz isso, depois ele ta dando a doida e pulando, poderia me ajudar. Exemplo das palnilhas:
Plan1 Plan2
Col.A Col.A
T1-1 T1-1 (Excluir)
T2-2 T1-1 (Excluir)
............ T2-2 (Excluir)
............ T2-2 (Excluir)
............ T3-3
............ T3-3

Se puder me ajudar agradeço a atenção! Estou tentando usar o código acima mas não esta dando certo! Obrigado....

 
Postado : 17/07/2014 7:21 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Bom dia!!

Tem como mandar seu arquivo modelo?

Att

 
Postado : 17/07/2014 8:44 am
(@wenpra)
Posts: 76
Estimable Member
Topic starter
 

Bom dia Alexandre!

Estou enviando abrindo a Planilha você vai ver que existe 4 planilhas: Clientes, Pedidos, Filtro1, Filtro2.
estou precisando de uma macro que faça o seguinte: pega o primeiro código da Plan"Filtro" (T1-1) e exclui as linhas da Plan"Cliente" e Plan"Pedidos" que tiverem o mesmo código "T1-1", depois vai para o segundo código da Plan"Filtro1" (T1-2) e faça também o mesmo nas duas planilhas. Desde já agradeço toda sua atenção.

 
Postado : 17/07/2014 9:17 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa tarde!!

Uma pergunta, na sua guia Clientes, os dados não repetem
CODIGO
T1-1
T1-3
T1-2
T2-1
T2-3
T2-4
T2-2
Então esse dados não serão delatados de acordo com o critério, correto?

Att

 
Postado : 17/07/2014 10:57 am
(@wenpra)
Posts: 76
Estimable Member
Topic starter
 

Boa tarde!!

Uma pergunta, na sua guia Clientes, os dados não repetem
CODIGO
T1-1
T1-3
T1-2
T2-1
T2-3
T2-4
T2-2
Então esse dados não serão delatados de acordo com o critério, correto?

Att

Não lá não se repete se tiver será só um?

 
Postado : 17/07/2014 11:03 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa tarde!!

Esse código deve ajudar, porém não foi testado!!!

Sub NaoTestado()
    Dim rRange1 As Range, rRange2 As Range, rRange3 As Range
    Dim lLoop As Long
     
    Set rRange2 = Plan3.Range("A2", Plan3.Cells(Rows.Count, "A").End(xlUp))
    Set rRange1 = Plan1.Range("A2", Plan1.Cells(Rows.Count, "O").End(xlUp))
    Set rRange3 = Plan2.Range("A2", Plan2.Cells(Rows.Count, "D").End(xlUp))
     
    With WorksheetFunction
        For lLoop = rRange1.Rows.Count To 1 Step -1
            If .CountIf(rRange2, rRange1.Cells(lLoop, 1)) > 0 _
            Then rRange1.Cells(lLoop, 1).EntireRow.Delete
        Next lLoop
    End With
    
    With WorksheetFunction
        For lLoop = rRange1.Rows.Count To 1 Step -1
            If .CountIf(rRange3, rRange1.Cells(lLoop, 1)) > 0 _
            Then rRange1.Cells(lLoop, 1).EntireRow.Delete
        Next lLoop
    End With
    
    
End Sub

Att

 
Postado : 17/07/2014 11:04 am
(@wenpra)
Posts: 76
Estimable Member
Topic starter
 

Boa tarde!!

Esse código deve ajudar, porém não foi testado!!!

Sub NaoTestado()
    Dim rRange1 As Range, rRange2 As Range, rRange3 As Range
    Dim lLoop As Long
     
    Set rRange2 = Plan3.Range("A2", Plan3.Cells(Rows.Count, "A").End(xlUp))
    Set rRange1 = Plan1.Range("A2", Plan1.Cells(Rows.Count, "O").End(xlUp))
    Set rRange3 = Plan2.Range("A2", Plan2.Cells(Rows.Count, "D").End(xlUp))
     
    With WorksheetFunction
        For lLoop = rRange1.Rows.Count To 1 Step -1
            If .CountIf(rRange2, rRange1.Cells(lLoop, 1)) > 0 _
            Then rRange1.Cells(lLoop, 1).EntireRow.Delete
        Next lLoop
    End With
    
    With WorksheetFunction
        For lLoop = rRange1.Rows.Count To 1 Step -1
            If .CountIf(rRange3, rRange1.Cells(lLoop, 1)) > 0 _
            Then rRange1.Cells(lLoop, 1).EntireRow.Delete
        Next lLoop
    End With
    
    
End Sub

Att

Alexandre na primeira planilha esta excluindo normal mas na segunda não excluiu nada.

 
Postado : 17/07/2014 11:21 am
(@wenpra)
Posts: 76
Estimable Member
Topic starter
 

Código corrigido deu certo agora!

Sub NaoTestado()
Dim rRange1 As Range, rRange2 As Range, rRange3 As Range
Dim lLoop As Long

Set rRange2 = Plan3.Range("A2", Plan3.Cells(Rows.Count, "A").End(xlUp))
Set rRange1 = Plan1.Range("A2", Plan1.Cells(Rows.Count, "O").End(xlUp))
Set rRange3 = Plan2.Range("A2", Plan2.Cells(Rows.Count, "D").End(xlUp))

With WorksheetFunction
For lLoop = rRange1.Rows.Count To 1 Step -1
If .CountIf(rRange2, rRange1.Cells(lLoop, 1)) > 0 _
Then rRange1.Cells(lLoop, 1).EntireRow.Delete
Next lLoop
End With

With WorksheetFunction
For lLoop = rRange3.Rows.Count To 1 Step -1
If .CountIf(rRange2, rRange3.Cells(lLoop, 1)) > 0 _
Then rRange3.Cells(lLoop, 1).EntireRow.Delete
Next lLoop
End With

End Sub

 
Postado : 17/07/2014 11:29 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa tarde!!

Que bom que resolveu, obrigado pelo retorno!

Att :)

 
Postado : 17/07/2014 12:24 pm