LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 396
Default Delete entire row if two cells are duplicate

Hi all, i have some code that i got from a search and it was apparantly
supplied by Tom Ogilvy. I need to understand it, as i have a lot of
lines and i need to loop down deleteing lines with duplicate numbers in
Column "A" & "D". However if Column "A" number is different and "D" is
the same it must not delete !! Any help would be greatly appreciated..

Sub DeleteDuplicateRows()
Dim RowNdx As Long
Dim ColNum As Integer
Dim rng As Range
ColNum = Selection(1).Column
For RowNdx = Selection(Selection.Cells.Count).Row To _
Selection(1).Row + 1 Step -1
If Cells(RowNdx, ColNum).Value = Cells(RowNdx - 1, ColNum).Value
Then
If rng Is Nothing Then
Set rng = Cells(RowNdx, ColNum)
Else
Set rng = Union(rng, Cells(RowNdx, ColNum))
End If
End If
Next RowNdx
If Not rng Is Nothing Then
rng.EntireRow.Delete
End If
End Sub

Les Stout

*** Sent via Developersdex http://www.developersdex.com ***
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete an entire row if two cells...... Red2003XLT Excel Discussion (Misc queries) 3 April 30th 08 09:48 PM
how do i delete duplicate cells in the same row Davidk Excel Discussion (Misc queries) 1 December 6th 07 12:00 AM
How do I delete duplicate cells? AYANG Excel Worksheet Functions 1 June 27th 06 06:29 AM
How do I delete duplicate records from an entire Excel workbook? Steven B. Excel Discussion (Misc queries) 0 December 6th 05 10:32 AM
Delete duplicate cells caseyoconnor10[_10_] Excel Programming 1 July 14th 04 01:57 AM


All times are GMT +1. The time now is 08:43 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"