Notifications
Clear all

Macro para excluir linhas conforme critério

9 Posts
3 Usuários
0 Reactions
1,305 Visualizações
(@wessley)
Posts: 0
New Member
Topic starter
 

Ola pessoal
Estou trabalhando com importaçao de arquivos txt e quando importo tem varias linhas. Eu precisava de uma macro que acha determinada palavra na coluna a e exclua a linha inteira que contenha essa palavra. Se poderem fazer uma macro dessas pra mim fico grato depois eu so iria ajustando.

 
Postado : 19/04/2015 8:28 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa tarde!!

Nos temos vários post na base do planilhando.
http://www.google.com.br/cse?cx=partner ... gsc.page=1

Considerando a coluna A, tente adaptar.

Sub Loop_Example()
'Fonte:http://www.rondebruin.nl/win/s4/win001.htm
    Dim Firstrow As Long
    Dim Lastrow As Long
    Dim Lrow As Long
    Dim CalcMode As Long
    Dim ViewMode As Long

    With Application
        CalcMode = .Calculation
        .Calculation = xlCalculationManual
        .ScreenUpdating = False
    End With
    'We use the ActiveSheet but you can replace this with
    'Sheets("MySheet")if you want
    With ActiveSheet
        'We select the sheet so we can change the window view
        .Select
        'If you are in Page Break Preview Or Page Layout view go
        'back to normal view, we do this for speed
        ViewMode = ActiveWindow.View
        ActiveWindow.View = xlNormalView
        'Turn off Page Breaks, we do this for speed
        .DisplayPageBreaks = False
        'Set the first and last row to loop through
        Firstrow = .UsedRange.Cells(1).Row
        Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
        'We loop from Lastrow to Firstrow (bottom to top)
        For Lrow = Lastrow To Firstrow Step -1
            'We check the values in the A column in this example
            With .Cells(Lrow, "A")
                If Not IsError(.Value) Then
                    If .Value = "ale" Then .EntireRow.Delete
                    'This will delete each row with the Value "ron"
                    'in Column A, case sensitive.
                End If
            End With
        Next Lrow
    End With

    ActiveWindow.View = ViewMode
    With Application
        .ScreenUpdating = True
        .Calculation = CalcMode
    End With

End Sub

Att

 
Postado : 20/04/2015 1:56 pm
(@wessley)
Posts: 0
New Member
Topic starter
 

desde ja obrigado.
tentei adaptar este código a minha planilha para excluir todas linhas inteiras na coluna A que contem a palavra "Unidade de Produção" mais fui um fracasso se puder me ajudar eu agradeço."segue em anexo."

 
Postado : 21/04/2015 8:43 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa tarde!!

Tente assim.

Sub AleVBA_15464()
    Dim c As Range
    Dim SrchRng
     
    Set SrchRng = ActiveSheet.Range("A1", ActiveSheet.Range("A65536").End(xlUp))
    Do
        Set c = SrchRng.Find("Unidade de Produção", LookIn:=xlValues)
        If Not c Is Nothing Then c.EntireRow.Delete
    Loop While Not c Is Nothing
End Sub

Att

 
Postado : 22/04/2015 9:00 am
(@edcronos)
Posts: 1006
Noble Member
 

o cara criou 2 post iguais
viewtopic.php?f=10&t=15494

eu já tinha até respondido

 
Postado : 22/04/2015 9:08 am
(@wessley)
Posts: 0
New Member
Topic starter
 

MUITO OBRIGADO alexandrevba EXPERIMENTEI E DEU CERTINHO TU RESOLVEU MEU PROBLEMA. VALEUUUU

 
Postado : 22/04/2015 2:42 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa tarde!!

Eu fico feliz em ajuda, obrigado pelo retorno!!

Att

 
Postado : 22/04/2015 2:47 pm
(@edcronos)
Posts: 1006
Noble Member
 

Apagaram o topico duplicado mas não incluiram minha resposta aqui,

quando eu respondi o outro topico dele não tinha visto esse aqui,

 
Postado : 22/04/2015 3:13 pm
(@wessley)
Posts: 0
New Member
Topic starter
 

OBRIGADO Edcronos PELA SUA ATENÇAO NO MEU TOPICO SE NAO TIVESSE APAGO O ANTERIOR CERTAMENTE TERIA CONSIDERADO SUA RESPOSTA ! DESDE JA AGRADEÇO A TODOS!! SAO PESSOAS COMO VCS QUE NOS AJUDAM NO NOSSO DIA DIA A MELHORAR NOSSO TRABALHO.VALEUU

 
Postado : 22/04/2015 5:58 pm