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

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

shew0387

New Member
Joined
Jan 13, 2005
Messages
14
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
 

Forum statistics

Threads
1,147,846
Messages
5,743,520
Members
423,801
Latest member
paulj4177

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
Top