View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default comparing rows and deletion

sree,

Maybe I now understand ?
The code was comparing each cell to the cell just above it.
If you are saying that the comparison should be between each
cell and the cell in the top row, then maybe the following
will do what you want...

Jim Cone
San Francisco, USA
'--------------------------
Sub ab()
Dim i As Long
Dim lngWide As Long
Dim lngLastRow As Long
Dim lngStartRow As Long
Dim blnAlert As Boolean
Dim c As Excel.Range
Dim cell As Excel.Range
Dim CompareCells As Excel.Range

lngLastRow = Cells(Rows.Count, 1).End(xlUp).Row
lngStartRow = 2 ' Must be 2 or more
lngWide = 100 ' ?
Set CompareCells = _
Cells(lngStartRow - 1, 1).Resize(lngStartRow - 1, lngWide).Cells

For i = lngStartRow To lngLastRow
Set cell = Cells(i, 1).Resize(1, lngWide).Cells
For Each c In cell
If c.Value CompareCells(lngStartRow - 1, c.Column).Value Then
blnAlert = True
Exit For
End If
Next 'c

If Not blnAlert Then
cell.ClearContents
Else
blnAlert = False
End If
Next 'i

Set c = Nothing
Set cell = Nothing
Set CompareCells = Nothing
End Sub
'--------------------------


"sreedhar"
wrote in message

hi jim,
i have try changing the code to <=, = ,< but also it is not clearing
any rows even if it true.
i have try for rows

1 0 1 1
0 1 1 0
0 0 0 0
1 0 0 0

but the code is not clearing or deteleting any row.what i want is for
the above rows it should delete 3rd and 4th row because they are
lessthan and equal to every cell in 1st row.
2nd row can't be deleted because 2nd cell " 1 "geraterthan the 2nd cell
"0" of 1st row.
so ,plz help me
thanks
sree