Delete Entire Row If Column C is Blank

J

John

I am trying to delete the entire row (and move all rows below up) if the
value in Column C for each row is blank. I have used the following code but
it throws up an Next Without For error, not sure where to go from here

Thanks



Sub DeleteZerosinIngredients()

With Application
.ScreenUpdating = False
.Calculation = xlManual
.MaxChange = 0.001
End With

Dim r As Range
For Each r In Selection

Sheets("Ingredient Mix").Select
With ActiveSheet
If Cells(r.Row, 3) = 0 Then r.EntireRow.Delete
Next

End With
With Application
.ScreenUpdating = True
.Calculation = xlAutomatic
.MaxChange = 0.001
End With
ActiveWorkbook.PrecisionAsDisplayed = False

End Sub
 
N

norika

John

You may try the following

Columns("C:C").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.Delete Shift:=xlUp

to replace
If Cells(r.Row, 3) = 0 Then r.EntireRow.Delete

HTH

noirk
 
D

Damien McBain

John said:
I am trying to delete the entire row (and move all rows below up) if
the value in Column C for each row is blank. I have used the
following code but it throws up an Next Without For error, not sure
where to go from here

Thanks



Sub DeleteZerosinIngredients()

With Application
.ScreenUpdating = False
.Calculation = xlManual
.MaxChange = 0.001
End With

Dim r As Range
For Each r In Selection

Sheets("Ingredient Mix").Select
With ActiveSheet
If Cells(r.Row, 3) = 0 Then r.EntireRow.Delete
Next

End With
With Application
.ScreenUpdating = True
.Calculation = xlAutomatic
.MaxChange = 0.001
End With
ActiveWorkbook.PrecisionAsDisplayed = False

End Sub

I do it like this:

Sub deleterows()

'first select the column you want to analyse

For Each c In Selection

If Cells(c.Row, c.Column) = "" Then
c.EntireRow.Delete
Else
End If
Next c

End Sub
 
J

John

Thanks but the code below still comes up with "Next without For" compile
error

Sub DeleteZerosinSalesMix()

With Application
.ScreenUpdating = False
.Calculation = xlManual
.MaxChange = 0.001
End With


For Each c In Selection

Sheets("Sales Mix").Select
With ActiveSheet


If Cells(c.Row, c.Column) = "" Then
c.EntireRow.Delete Shift:=xlUp
Else
End If
Next c

End With
With Application
.ScreenUpdating = True
.Calculation = xlAutomatic
.MaxChange = 0.001
End With
ActiveWorkbook.PrecisionAsDisplayed = False

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top