Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
  • Avatar do usuário
Por BrunoSP
Posts
#14834
Pessoal, estou tento dificuldade em gerar uma macro condicional, onde, conforme exemplo anexo, preciso que apague uma linha (deletar a linha e não somente dados) se numa coluna for maior que 10 e em outra se tiver dados escritos.

A macro deverá varrer 60 mil linhas e excluir as linhas de acordo com as condições informadas.
#14838
Valew pessoal, achei um ótimo cód para isso. Acontece que executo duas vezes para 2 colunas... acho q dá para adaptar no mesmo cod, mas chamo ele novamente.

Sub Loop_Example()
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, "CC")

If Not IsError(.Value) Then

If .Value >= 11 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
#14841
Boa tarde!!
Código: Selecionar todos
Sub AleVBA_2955()
    Dim Lastrow As Long
    Dim i As Long
    Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = Lastrow To 2 Step -1
        If Cells(i, "B").Value2 > 10 And Cells(i, "C").Value2 <> "" Then
            Rows(i).Delete
        End If
    Next i
End Sub
Att
Por BrunoSP
Posts
#14848
alexandrevba , obrigado pelo retorno. Gostei do seu cód e do SECUNA, são enxutos, e assim, é mais simples para adaptar também para outras necessidades. Obrigado.

Nesse código porém, está com AND, ou seja, os dois requisitos devem ser atendidos para que ele exclua a linha. E no caso, o correto seria OU, pois tanto um dos dois requisitos acima devem ser executados, ou >10 ou Vazio. Como que altera, basta colocar OR?
Por BrunoSP
Posts
#14849
SECUNA, obrigado pelo retorno. Seu código funciona, porém, num teste de 20 linhas, precisei executar o código algumas vezes para que ele pudesse retirar todas as células que possuem essa condição. Tavez na contagem, ou proxima checagem, ele pule uma linha devido a exclusão de outra.
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord