DELETE Row if Cell Value in Column is Zero 0

HotNumbers

Well-known Member
Joined
Feb 14, 2005
Messages
732
Why can't i get this to work. I need to delete the row if a cell in P10:P50000 has a 0


Part of the code

Dim ChkRange As Range
Set ChkRange = Range("p10:p50000")

Dim cell As Range

For Each cell In ChkRange
If cell = "0" Then
cell.EntireRow.Delete
End If
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
It should be 0 not "0" plus you need to loop backwards when deleting rows. Try

Code:
For i = 50000 To 10 Step -1
    If Range("P" & i).Value = 0 Then Rows(i).Delete
Next i
 
Upvote 0
VoG

Thanks a million... first for a short code that really works... and second for your explination...
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,908
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top