Erro na execução de...
 
Notifications
Clear all

Erro na execução de um MACRO

7 Posts
2 Usuários
0 Reactions
745 Visualizações
(@megasup)
Posts: 4
Active Member
Topic starter
 

Tudo bem pessoal, estou com um problema na hora de executar um macro, o erro que aparece é (ERRO EM TEMPO DE EXECUÇÃO '91': A VARIÁVEL DO OBJETO OU NA VARRÁVEL DO BLOCO 'WITH' NÃO FOI DEFINIDA)

essa é a macro que tento executar

Sub Procura_E_Destroi_Correcao_2()

Dim email As String
Dim emailrange As String

Range("B1").Select
Selection.Delete Shift:=xlUp
Selection.End(xlDown).Select
Selection.Delete Shift:=xlUp
Range("B1").Select

Do While Not IsEmpty(ActiveCell)
email = ActiveCell.Value
emailrange = ActiveCell.Address

Columns("A:A").Select
Selection.Find(What:=email, After:=ActiveCell, LookIn:= _
xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=True, SearchFormat:=False).Select <----------- ( O ERRO É REFERENTE A ESSA LINHA!!!!)

Selection.Delete Shift:=xlUp

Range(emailrange).Select
ActiveCell.Offset(1, 0).Select
emailrange = ActiveCell.Select

Loop

End Sub

O objetivo dessa macro, é deletar emails da coluna A em relação com a coluna B.

Tem como alguem me ajudar por favor.
Valew fico no aguardo

 
Postado : 17/04/2014 11:48 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa tarde!!

Se pode mandar seu arquivo modelo, eu não tive problemas ao rodar a macro.

Att

 
Postado : 17/04/2014 11:57 am
(@megasup)
Posts: 4
Active Member
Topic starter
 

Vou anexar aqui
neste link tem o macro, o arquivo que preciso arrumar, e um tutorial que recebi.
http://www.sendspace.com/file/22ao4y

Fico no aguardo de Respostas
Obrigado

 
Postado : 17/04/2014 12:01 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa tarde!!

Porque há duas colunas com emails, eu não entendi, seria deletar tudo que contém "email" de cada coluna (A e B) ou só de uma coluna?

Caso seja só de uma coluna.

Sub AleVBA_11352()
    Dim c As Range
    Dim SrchRng
     
    Set SrchRng = ActiveSheet.Range("A1", ActiveSheet.Range("A65536").End(xlUp))
    Do
        Set c = SrchRng.Find("mail", LookIn:=xlValues)
        If Not c Is Nothing Then c.EntireRow.Delete
    Loop While Not c Is Nothing
End Sub

Att

 
Postado : 17/04/2014 12:19 pm
(@megasup)
Posts: 4
Active Member
Topic starter
 

Tem duas colunas, pq os emails que estao na coluna B tem que ser deletado da coluna A.

 
Postado : 17/04/2014 12:24 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa tarde!!
Não testado!!

Option Explicit
    
Sub CompararDuasColunas_AleVBA()
Dim rngColA As Range
Dim rngColB As Range
Dim rngCell As Range
    
    With Plan1
        Set rngColA = .Range(.Cells(2, 1), .Cells(.Rows.Count, 1).End(xlUp))
        Set rngColB = .Range(.Cells(2, 2), .Cells(.Rows.Count, 2).End(xlUp))
        
        For Each rngCell In rngColA.Cells
            If Not IsError(Application.Match(rngCell.Value, rngColB, 0)) Then
                rngCell.Interior.ColorIndex = 15 'vai colorir o que for iqual a B
                rngCell.Delete
            End If
        Next
    End With
End Sub
 
Postado : 17/04/2014 12:46 pm
(@megasup)
Posts: 4
Active Member
Topic starter
 

Acho que esse vai servir para oque eu quero vou testar aqui, MUITO OBRIGADO Mesmo
Att
Leandro Crepaldi

 
Postado : 17/04/2014 1:07 pm