I have a formula to delete cells that have a zero value which is shown
below
Dim cell As Range
For Each cell In Cells.SpecialCells(xlCellTypeConstants, xlNumbers)
If cell.Value = 0 Then cell.Delete
Next cell
That works fine but im trying to delete the whole line and not just the
cells that have zero in them.
I have a workbook which is set up as follows
outstanding paid paid paid outstandingitem a 300.00 100.00 200.00 0.00
item b 40.00 5.00 35.00
Item c 33.00 8.00 25.00
Im trying to delete the whole line if the outstanding amount shown at
the end of the line is zero. i.e the top line (the line horizontally
from item a to 0.00)
Would I be able to set it into a macro that deletes the zero amounts
first and then transfer all the other data which has amount other than
zero into a new workbook.--
tweacle
One way:
Maybe something like:
Option Explicit
Sub testme()
Dim rng As Range
Dim wks As Worksheet
Dim myCell As Range
Dim DelRng As Range
Set wks = Worksheets(quot;Sheet1quot;)
With wks
Set rng = .Range(quot;D2quot;, .Cells(.Rows.Count, quot;Dquot;).End(xlUp))
End With
For Each myCell In rng.Cells
If IsEmpty(myCell) = False Then
If myCell.Value = 0 Then
If DelRng Is Nothing Then
Set DelRng = myCell
Else
Set DelRng = Union(myCell, DelRng)
End If
End If
End If
Next myCell
If DelRng Is Nothing Then
'do nothing
Else
DelRng.Select
'or (after testing!)
'DelRng.EntireRow.Delete
End If
End Sub
And after you've deleted the rows with 0's in column D, you can do whatever you
want with the other data.
tweacle wrote:
gt;
gt; I have a formula to delete cells that have a zero value which is shown
gt; below
gt;
gt; Dim cell As Range
gt;
gt; For Each cell In Cells.SpecialCells(xlCellTypeConstants, xlNumbers)
gt; If cell.Value = 0 Then cell.Delete
gt; Next cell
gt;
gt; That works fine but im trying to delete the whole line and not just the
gt; cells that have zero in them.
gt; I have a workbook which is set up as follows
gt;
gt; outstanding paid paid paid outstanding
gt;
gt; item a 300.00 100.00 200.00 0.00
gt; item b 40.00 5.00 35.00
gt; Item c 33.00 8.00 25.00
gt;
gt; Im trying to delete the whole line if the outstanding amount shown at
gt; the end of the line is zero. i.e the top line (the line horizontally
gt; from item a to 0.00)
gt;
gt; Would I be able to set it into a macro that deletes the zero amounts
gt; first and then transfer all the other data which has amount other than
gt; zero into a new workbook.
gt;
gt; --
gt; tweacle
--
Dave Peterson
- Sep 23 Tue 2008 20:46
delete zero value's using a macro
close
全站熱搜
留言列表
發表留言