View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Zone Zone is offline
external usenet poster
 
Posts: 269
Default Delete row problem, could some help me on that?

For one thing, when i = 1, there is no cell i-1, "B". Try
For i=LastRow to 2 step -1
James
ina wrote:
Hello guys,

I have a problem with this small sub, I would like to delete the row it
the value of one cell is egual of the value of cell + 1 but I have this
problem delete method of range class failed and I do not know why?

Sub deletequalrow()
Dim LastRow As Long
Dim i As Long


With ActiveSheet.UsedRange
LastRow = .Cells(.Cells.Count).Row
End With


For i = LastRow To 1 Step -1
If Cells(i, "B").Value = Cells(i - 1, "B").Value Then
Rows(i).EntireRow.Delete
End If
Next i
End Sub

Ina