martian
11-12-2008, 06:41 PM
Sub DeleteRow()
Dim sh As Worksheet
Dim rg As Range
For Each sh In ThisWorkbook.Worksheets
Set rg = sh.Cells(65536, "C").End(xlUp)
Do While rg.Row >= 2
If rg.Value = 0 Then
Set rg = rg.Offset(-1, 0)
rg.Offset(1, 0).EntireRow.Delete
Else
Set rg = rg.Offset(-1, 0)
End If
Loop
Next
Set sh=Nothing
Set rg=Nothing
End Sub
This program runs well.
But when i changed this parts:
If rg.Value = 0 Then
Set rg = rg.Offset(-1, 0)
rg.Offset(1, 0).EntireRow.Delete
To:
If rg.Value=0 Then
rg.EntireRow.Delete
Set rg = rg.Offset(-1, 0)
There was an error occurred:runtime error '424';no object
and maybe it's the reason that i deleted the variant 'rg' (rg.EntireRow.Delete )
but i am puzzled with this:
if rg gets the value 'cells(3,3)' and after i run "rg.entirerow.delete"
the range cells(3,3) is still there.
Dim sh As Worksheet
Dim rg As Range
For Each sh In ThisWorkbook.Worksheets
Set rg = sh.Cells(65536, "C").End(xlUp)
Do While rg.Row >= 2
If rg.Value = 0 Then
Set rg = rg.Offset(-1, 0)
rg.Offset(1, 0).EntireRow.Delete
Else
Set rg = rg.Offset(-1, 0)
End If
Loop
Next
Set sh=Nothing
Set rg=Nothing
End Sub
This program runs well.
But when i changed this parts:
If rg.Value = 0 Then
Set rg = rg.Offset(-1, 0)
rg.Offset(1, 0).EntireRow.Delete
To:
If rg.Value=0 Then
rg.EntireRow.Delete
Set rg = rg.Offset(-1, 0)
There was an error occurred:runtime error '424';no object
and maybe it's the reason that i deleted the variant 'rg' (rg.EntireRow.Delete )
but i am puzzled with this:
if rg gets the value 'cells(3,3)' and after i run "rg.entirerow.delete"
the range cells(3,3) is still there.