dimanche 14 juin 2020

If then loop structure to delete rows according to criteria

My code checks column Q for the string "No data available" and if it finds it it deletes the entire row. I want the program to also check column J for 0 and delete the entire row if it finds it, but I'm not sure how I structure the loop in order to achieve this:

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

ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView


.DisplayPageBreaks = False


FirstRow = .UsedRange.Cells(1).Row
lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row



If Not IsError(.Value) Then

If .Value = "No data available" Then .EntireRow.Delete
'If Not IsError(.Value) Then


'End If
End If

End With

Next lRow

'End With


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

End Sub

Aucun commentaire:

Enregistrer un commentaire