View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Balan Balan is offline
external usenet poster
 
Posts: 70
Default Deleting duplicate rows

I was learning excel programming from microsoft's training site. I wanted to
test write a programme to delete rows having duplicate data. The data table
has 10 rows on columns B and C. Where the data on both columns B and C are
repeated in subsequent rows ( once or more than once), such duplicate rows to
be deleted. I wrote the following macro and ran it:
--------
Sub DuplicateRowRemover()
x = 3
y = 4
Do While Cells(x, 2).Value < " "
Do While Cells(y, 2).Value < ""
If (Cells(x, 2).Value = Cells(y, 2).Value) _
And (Cells(x, 3).Value = Cells(y, 3).Value) Then
Cells(y, 2).EntireRow.Delete
Else
y = y + 1
End If
Loop
x = x + 1
y = x + 1
Loop

----------

The programme is working correctly. All duplicate rows were deleted and
only unique records remained. However, at the end of running the programme,
I get an error message. The yellow debug line was the second 'Do while '
statement. the value of 'y' when I take the cursor near it is showing 65537.
As the Do while should have stopped at the end of the 10th row as 11th
onwards were blank ( i.e., " " as shown in Do While statement), I am puzzled
why this is happening. Can any one help ? Thanks in advance to volunteer.

Balan