delete cells containing a zero in one column

shew0387

New Member
Joined
Jan 13, 2005
Messages
14
I'm trying to just delete the cells instead of the entire row that contain zero's. This code finds the first zero value in a cell, deletes it, but then it shifts the values in adjacent columns over one to the left, but only in the row where it found the first zero value cell...if you can, please help. Thanks

Sub Delete_zero_cells()
Range("A2").Select
While IsEmpty(ActiveCell) = False

If ActiveCell.Value = "0" Then
ActiveCell.Cells.Delete
Else
ActiveCell.Offset(1, 0).Activate

End If
Wend
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
okay, i'm a bonehead - I added the "shift:=xlUp" after deleting the cells and that seems to be the fix... Thanks for stopping by and reading a conversation between myself...

Sub Delete_zero_cells()
Range("A2").Select
While IsEmpty(ActiveCell) = False

If ActiveCell.Value = "0" Then
ActiveCell.Cells.Delete shift:=xlUp
Else
ActiveCell.Offset(1, 0).Activate

End If
Wend
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,552
Members
449,088
Latest member
davidcom

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