Hi Met,
Deleting records containing zeros is not quite as simple as deleting blanks.
And it depends on how many records there are.
Some thoughts.
1. Filter them (& blanks) out via SQL. This is really efficient. Preferably when creating the table. Or when creating a new table from your existing table.
2. For one row only, and it depends on how you've referred to the row. Something like
Code:
With Range("Q" & Your_Row_Number)
If .Value = 0 Then .EntireRow.Delete
End With
3. If there aren't too many records, loop through all cells applying something like number 2 above each time. If looping, probably best to loop from the last record backwards to the first.
4. Without fully coding it. If there are many records, either filter the data (using Autofilter) on zeros and then using
Code:
'your range reference'.SpecialCells.xlCellTypeVisible.EntireRowDelete
or, temporarily add one extra column (only if you are not already at Excel's maximum of 256 columns) and have a formula the results of which you can test via SpecialCells to distinguish between the records you want and don't want. Again, "EntireRow.Delete". Then delete the temporary column.
Modify to suit, something like this code I use in my Excel personal macros.
Code:
Sub DeleteRowsWhereZeroInCurrentColumn()
Application.ScreenUpdating = False
Dim lCol As Long
lCol = ActiveCell.Column
'Enter new first column (avoids upsetting any filters); would fail if already using 256 columns.
With Range(Cells(1, lCol), Cells(65536, lCol).End(xlUp)).Offset(0, 1 - lCol)
.EntireColumn.Insert
With .Offset(0, -1)
.FormulaR1C1 = "=1/RC[" & lCol & "]"
.Value = .Value
.Range("A1").ClearContents
On Error Resume Next
.SpecialCells(xlCellTypeConstants, xlErrors).EntireRow.Delete
Err.Clear
.EntireColumn.Delete
End With
End With
End Sub
regards,
Fazza