View Single Post
  #10   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,

The code is getting complicated.
The following may do what you want, however it is difficult
to determine if the correct rows are being deleted.
See how it works for you.
Note: change the "lngWide" setting to the correct number of columns.
I hope there are no more "additional" requirements.

'--------------------------
Sub ab()
Dim i As Long
Dim N 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

lngStartRow = 2 ' Must be 2 or more
lngWide = 10 ' ?
Application.ScreenUpdating = False

Do 'Start a loop
lngLastRow = Cells(Rows.Count, 1).End(xlUp).Row
Set CompareCells = _
Cells(lngStartRow - 1 + N, 1).Resize(1, lngWide).Cells

'Start another loop from the bottom up.
For i = lngLastRow To (lngStartRow + N) Step -1
Set cell = Cells(i, 1).Resize(1, lngWide).Cells

'Loop from left to right
For Each c In cell
If c.Value CompareCells(1, c.Column).Value Then
blnAlert = True
Exit For
End If
Next 'c

If Not blnAlert Then
cell.Delete shift:=xlUp 'Remove the row
Else
blnAlert = False
End If
Next 'i
N = N + 1
Loop Until N = (lngLastRow - lngStartRow - N)

Application.ScreenUpdating = True
Set c = Nothing
Set cell = Nothing
Set CompareCells = Nothing
End Sub
'--------------------------

Regards,
Jim Cone


"sreedhar"
wrote in message

hi jim,
it is working for first row thanks a lot ,
my problem is
after comparing with the first row it should then comparing with 2nd
row with all other rows and delete.
after completion of 2nd row it should use 3rd row to compare with all
other rows
and delete.
like this it should follow all the rows till end
my idea for this is after clear any row we have call this marco to fill
up the empty blanks in the excel sheet.

Sub RemoveBlankRows()
Columns("A:A").SpecialCells(xlCellTypeBlanks).Dele te Shift:=xlUp
End Sub

and then agin go for other row comparsion and so on.
plz, help me regarding this
thank u
sree