PDA

View Full Version : removing 0's macro based on columns



indep
05-20-2008, 08:16 AM
Hi,
I have an excel file that has 15 columns , the first 3 will contain data but the next 12 are the periods of the month period 1 to 12 and I want a macro to see if period 01 to period 12 are all 0's to delete that entire row. Can you please let me know what the vba code would be, i dont want it sorted I need it to be in the exam same order but if P01 to p02 are all 0's then to delete that whole row including the first 3 columns that contain data

Thanks

Bob Phillips
05-20-2008, 08:33 AM
Public Sub ProcessData()
Dim i As Long
Dim LastRow As Long
With Application

.ScreenUpdating = False
.Calculation = xlCalculationManual
End With

With ActiveSheet

LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = LastRow To 1 Step -1

If Application.CountIf(.Cells(i, "D").Resize(, 12), 0) = 12 Then

.Rows(i).Delete
End If
Next i

End With

With Application

.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With

End Sub