PC Review


Reply
Thread Tools Rate Thread

Clear duplicate values

 
 
Member
Join Date: Jul 2007
Posts: 26
 
      27th Feb 2008
To All,
I am trying to sort an array (AB27:AC44) then compare the value in two cells (AB28 & AC28) with the two cells above (AB27:AC28) if they are the same then clear AB28 & AC29, then resort, then select the next down and compare. The following is my code which I can't get to work as I want.
Sub CompareCellValueAndClearExtraCells()
Application.ScreenUpdating = False
Dim MyCounter
MyCounter = 1
''Sort the values
Range("AB27:AC44").Select
Selection.sort Key1:=Range("AC27"), Order1:=xlAscending, Key2:=Range( _
"AB27"), Order2:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortNormal

''Select the second on the list and delete duplicates
Range("AB28").Select
Do Until MyCounter = 17
MyCounter = MyCounter + 1
If ActiveCell.Value = ActiveCell.Offset(-1, 0) Then
If ActiveCell.Offset(0, 1).Value = ActiveCell.Offset(-1, 1) Then
ActiveCell.Range("A1:B1").Select
Selection.ClearContents
End If
End If
Range("AB27:AC44").Select
Selection.sort Key1:=Range("AC27"), Order1:=xlAscending, Key2:=Range( _
"AB27"), Order2:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortNormal

Range("AB28").Select
If ActiveCell.Value = ActiveCell.Offset(-1, 0) Then
If ActiveCell.Offset(0, 1).Value = ActiveCell.Offset(-1, 1) Then
ActiveCell.Range("A1:B1").Select
Selection.ClearContents
Else
ActiveCell.Offset(1, 0).Select
End If
End If
Loop

End Sub
Thanks In advance for any help.
Geoffrey Barnard
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
duplicate data in range clear contents baha17@gmail.com Microsoft Excel Programming 1 18th Nov 2009 03:18 PM
Duplicate Not Allowed, clear field Pat Briggs Microsoft Access VBA Modules 12 1st Jul 2009 05:32 PM
RE: How to clear the lowest 10 values from a list of 30 values Jerry W. Lewis Microsoft Excel New Users 0 3rd Apr 2009 07:40 AM
Re: How to clear the lowest 10 values from a list of 30 values Don Guillett Microsoft Excel New Users 1 3rd Apr 2009 12:19 AM
Why does this code remove Duplicate Values, by showing only 1, but it does NOT show Unique values for some reason ? Corey Microsoft Excel Programming 4 23rd Feb 2007 02:00 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:31 PM.