Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Remove duplicates

Thanks OssieMac,
This works great.
Regards, Stan
"OssieMac" wrote in message
...
OK Stanley done. It just clears the cells now instead of deleting the
rows.
Have also modified a couple of other bits that makes the code more generic
therefore replace all of the code.

Sub RemoveDuplicates()

Dim rngToTest As Range
Dim rngTofind As Range
Dim cel As Range
Dim firstAddress As String
Dim i As Long
Dim rngSave As Range

With ActiveSheet
Set rngToTest = Range(.Cells(2, "A"), _
.Cells(.Rows.Count, "A").End(xlUp))

'Insert a temporary column to hold delete flag
.Columns("B:B").Insert Shift:=xlToRight

End With

Application.ScreenUpdating = False

For Each rngTofind In rngToTest

'Test if value already searched
With rngToTest
If rngTofind.Offset(0, 1) < "Delete" Then
Set cel = .Columns("A:A").Find(What:=rngTofind.Value, _
After:=.Cells(.Rows.Count, "A"), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

Set rngSave = Nothing
If Not cel Is Nothing Then 'Found
firstAddress = cel.Address
Set rngSave = cel 'Save the location
Set cel = .FindNext(cel)
Do While Not cel Is Nothing And _
cel.Address < firstAddress
cel.Offset(0, 1) = "Delete"
rngSave.Font.Bold = True 'Bold original find
Set cel = .FindNext(cel)
Loop
End If
End If
End With
Next rngTofind

With rngToTest
'Work backwards when deleting rows
For i = .Rows.Count To 1 Step -1
If .Cells(i, 1).Offset(0, 1) = "Delete" Then
.Cells(i, 1).Clear
End If
Next i
End With

'Delete the temporary column
With ActiveSheet
.Columns("B:B").Delete
End With

Application.ScreenUpdating = True

End Sub


--
Regards,

OssieMac




Reply
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
Remove duplicates jennifer Excel Worksheet Functions 2 August 28th 09 07:26 PM
remove duplicates need help faceliftguide Setting up and Configuration of Excel 3 July 14th 09 02:27 PM
Remove Duplicates Joe Excel Worksheet Functions 2 February 13th 09 11:58 PM
How to remove duplicates? Lakewoodsale Excel Discussion (Misc queries) 2 January 25th 08 10:31 PM
Remove duplicates Tuttamay77 Excel Discussion (Misc queries) 4 May 12th 06 10:56 PM


All times are GMT +1. The time now is 06:57 PM.

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"