Good afternoon everybody!
After I received the answers to the topics I posted, I decided to apply those concepts in a previous work that had already ended. Basically I want to optimize the filtering of "0" values in two different columns. But to avoid errors, I used the logical operator NOT together with the IsEmpty () method so that all the filled lines were traversed with the WHILE and FOR decision structures, ensuring that all "0" were checked, also preventing them from being confused with empty cells.
However, the code can certainly be optimized, especially the filtering I did on the IF, which was very structured and takes all the cells in an entire column, making the process take longer. Trying to apply what I learned before, I was unable to produce the result I wanted for some reason (and unfortunately I no longer have the code I generated a short time ago).
So how can I make this task simpler? I will be very grateful if you have that answer. : - D
After I received the answers to the topics I posted, I decided to apply those concepts in a previous work that had already ended. Basically I want to optimize the filtering of "0" values in two different columns. But to avoid errors, I used the logical operator NOT together with the IsEmpty () method so that all the filled lines were traversed with the WHILE and FOR decision structures, ensuring that all "0" were checked, also preventing them from being confused with empty cells.
However, the code can certainly be optimized, especially the filtering I did on the IF, which was very structured and takes all the cells in an entire column, making the process take longer. Trying to apply what I learned before, I was unable to produce the result I wanted for some reason (and unfortunately I no longer have the code I generated a short time ago).
So how can I make this task simpler? I will be very grateful if you have that answer. : - D
VBA Code:
Sub deleteZeros()
Application.ScreenUpdating = False
Dim W As Worksheet
Dim rowNumber As Long
Set W = Sheets("Sheet1")
W.Select
rowNumber = 2
While Not IsEmpty(W.Cells(rowNumber, "AB").Value) And Not IsEmpty(W.Cells(rowNumber, "AI").Value
Do Until (W.Cells(rowNumber, "AB").Value = 0) And (W.Cells(rowNumber, "AI") = 0)
rowNumber = rowNumber + 1
Loop
If ((W.Cells(rowNumber, "AB").Value = 0) And (W.Cells(rowNumber, "AI") = 0)) And (Not IsEmpty(W.Cells(rowNumber, "AB").Value) And Not IsEmpty(W.Cells(rowNumber, "AI").Value)) Then
W.Range("AB1").Select
ActiveSheet.Range("$A$1:$AQ$1048576").AutoFilter Field:=28, Criteria1:="0"
W.Range("AI1").Select
ActiveSheet.Range("$A$1:$AQ$1048576").AutoFilter Field:=35, Criteria1:="0"
ActiveSheet.Range("A2:AQ" & Range("A" & Rows.Count).End(xlUp).Row).SpecialCells(xlVisible).EntireRow.Delete
W.ShowAllData
W.Cells(1, 1).Select
MsgBox ("The rows have been successfully deleted!")
End If
Wend
Application.ScreenUpdating = True
End Sub