If column V="0" , delete the entire row????


Posted by Ren on December 27, 2001 1:16 PM

If column V="0" , delete the entire row????

Posted by Jacob on December 27, 2001 1:41 PM

Hi

This macro will do the trick, just insert a new macro and paste this code:


Sub DeleteIt()
Dim LastRow as integer

LastRow = range("V65536").end(xlup).row

for x = LastRow to 1 step -1

If range("V" & x).value = 0 Then
rows(x).delete shift:=xlup
else
next x

end sub


Hope this helps

Jacob

Posted by Joe Was on December 27, 2001 2:47 PM

Sub DRow()
'Find all the rows for which column "V" = "0" and delete it.

Application.ScreenUpdating = False
Worksheets("Sheet1").Select
Range("V1").Select
For Each r In Worksheets("Sheet1").UsedRange.Rows
n = r.Row
If Worksheets("Sheet1").Cells(n, 22) = "0" Then
Worksheets("Sheet1").Cells(n, 22).Select
Selection.EntireRow.Delete
End If
Next r
Application.ScreenUpdating = True
'Range("A1").Select
End Sub

Note: This will work, but in some cases you will need to run it more than once to get all the "0's." I don't know why this is, but I suspect that "Each r in UsedRange" is the problem?
In any case this will get you a start?

The rows it misses on the first pass are 4 or more consecutive rows of "0" it only gets the first two in that case. I had to re-run the macro up to 3 times to get all the "0" rows deleted in my test sheet? JSW



Posted by Joe Was on December 27, 2001 3:15 PM

Jacob's code works, but needs a small fix

Sub DeleteIt()
Dim LastRow As Integer

LastRow = Range("V65536").End(xlUp).Row

For x = LastRow To 1 Step -1

If Range("V" & x).Value = 0 Then
Rows(x).Delete shift:=xlUp
Else
End If
Next x

End Sub

He just left out the "End If" I tested it and it works great, good job. JSW

: If column V="0" , delete the entire row????