Página 1 de 1

Selecionar Procurar e Excluir

Enviado: 04 Mai 2020 às 14:14
por JuniorDist
Olá pessoal, estou com um problema (que talvez seja fácil de resolver mas estou quebrando a cabeça kkk), tenho duas listas de e-mails, A e B, a lista A contem e-mails que precisam ser excluídos da lista B, porém são mais de 200 linhas de contatos e é muito chato ir buscado manualmente na lista B e ir excluindo, teria alguma maneira mais fácil de resolver o problema?

Re: Selecionar Procurar e Excluir

Enviado: 04 Mai 2020 às 14:59
por babdallas
Veja se ajuda.
Código: Selecionar todos
Public Sub Apagar_Email_ListaA_na_ListaB()
    Dim vrtDadosA           As Variant
    Dim vrtDadosB           As Variant
    Dim strDadosC()         As String
    Dim lngUltLinA          As Long
    Dim lngUltLinB          As Long
    Dim lngContC            As Long
    Dim lngCont             As Long
    
    
    With Planilha1
        lngUltLinA = .Cells(.Rows.Count, 1).End(xlUp).Row
        lngUltLinB = .Cells(.Rows.Count, 2).End(xlUp).Row
        
        vrtDadosA = .Range("A2:A" & lngUltLinA).Value2
        vrtDadosB = .Range("B2:B" & lngUltLinB).Value2
        
        ReDim strDadosC(1 To lngUltLinA) As String
        
        For lngCont = LBound(vrtDadosB) To UBound(vrtDadosB)
            If Application.WorksheetFunction.CountIf(.Range("A2:A" & lngUltLinA), vrtDadosB(lngCont, 1)) = 0 Then
                lngContC = lngContC + 1
                strDadosC(lngContC) = vrtDadosB(lngCont, 1)
            End If
        Next lngCont
        
        ReDim Preserve strDadosC(1 To lngContC) As String
        
        .Range(.Cells(2, 2), .Cells(lngUltLinB, 2)).ClearContents
        .Range("B2:B" & lngContC + 1).Value2 = Application.Transpose(strDadosC)
    End With
    
End Sub

Selecionar Procurar e Excluir

Enviado: 04 Mai 2020 às 16:03
por JuniorDist
Perfeitooooo! Muito obrigado amigo, salvou a minha vida :lol: :D