View Single Post
  #3   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,
?
Jim Cone
San Francisco, USA
'-------------------------
Sub ab()
Dim lastrow As Long, i As Long
Dim cell As Range, c As Range
'Dim sStr1 As String, sStr2 As String
Dim blnAlert As Boolean
lastrow = Cells(Rows.Count, 1).End(xlUp).Row

For i = 2 To lastrow
Set cell = Cells(i, 1).Resize(1, 100)
'sStr1 = "": sStr2 = ""
For Each c In cell
If c.Value c(0, 1).Value Then
blnAlert = True
Exit For
End If
'sStr2 = sStr2 & c.Value
'sStr1 = sStr1 & c.Offset(-1, 0).Value
Next
'If sStr2 < sStr1 Then
If Not blnAlert Then
cell.ClearContents
Else
blnAlert = False
End If
Next
Set c = Nothing
Set cell = Nothing
End Sub
'--------------------------

"sreedhar"
wrote in message

hi,
i want to compare rows and delete the rows
previously i got an marco help from the group but it is comparing the
whole string of the row
for example

it is comparing rows

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

for these rows the marco is deleting the thrid row because 1010 is
0100
but it shouldn't delete it because we have to compare by cell by cell
in the whole row

1 0 ,0 <1 ,1 0,0 = 0

but 0<1
so it should not delete the row.
the marco is as follows

Sub ab()
Dim lastrow As Long, i As Long
Dim cell As Range, c As Range
Dim sStr1 As String, sStr2 As String
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastrow
Set cell = Cells(i, 1).Resize(1, 100)
sStr1 = "": sStr2 = ""
For Each c In cell
sStr2 = sStr2 & c.Value
sStr1 = sStr1 & c.Offset(-1, 0).Value
Next
If sStr2 < sStr1 Then
cell.ClearContents
End If
Next
End Sub

but i need a marco which compares cell by cell in the whole row and
delete if all cells are than all cells in the other row else compare
with other row till end of xlsheet.
So, can any one plz help me A.S.P
thanks
sree