Macro that deltes when value is zero, not blank

jillzz

New Member
Joined
Nov 15, 2005
Messages
6
I have code that looks at a column of data and deletes any rows with zeros in them... here it is


Dim Col As Integer
Dim LastRow As Long

LastRow = ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).Row
'Now give a numerical no. of column you want to search through
Col = Application.InputBox(prompt:="Give a column number, please:")

Do While LastRow > 1
Cells(LastRow, Col).Select
If Cells(LastRow, Col) = 0 Then
Rows(LastRow).EntireRow.Delete
End If
LastRow = LastRow - 1
Loop

The problem is it deletes blank cells as well.
Can anyone help with how to delete only the zero rows and leave the blank rows?
Thanks[/code]
 
Try the untested
Code:
If not isempty(cells(lastrow,col).value) and cells(lastrow,col).value=0 then
jillzz said:
I have code that looks at a column of data and deletes any rows with zeros in them... here it is


Dim Col As Integer
Dim LastRow As Long

LastRow = ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).Row
'Now give a numerical no. of column you want to search through
Col = Application.InputBox(prompt:="Give a column number, please:")

Do While LastRow > 1
Cells(LastRow, Col).Select
If Cells(LastRow, Col) = 0 Then
Rows(LastRow).EntireRow.Delete
End If
LastRow = LastRow - 1
Loop

The problem is it deletes blank cells as well.
Can anyone help with how to delete only the zero rows and leave the blank rows?
Thanks[/code]
 
Upvote 0

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