Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Remove Duplicate Pairs(2 Columns)


Hello. I have 2 columns order_no and item_no. Duplicates are allowed i
each column separately, however I would like to remove all duplicat
"pairs" of order_no and item_no. So for instance (order_no, item_no) -
[(1, 4) and (1, 4)] would be deleted, but [(1, 3) and (1, 4)] OR [(1, 3
and (2, 3)] would be be allowed. Basically my primary key is th
superkey of both order_no and item_no which is why I can't hav
duplicates. The 2 columns are right next to each other (order_no i
column C, item_no is column D).

Thanks!
[kyle

--
deathswa
-----------------------------------------------------------------------
deathswan's Profile: http://www.excelforum.com/member.php...fo&userid=3306
View this thread: http://www.excelforum.com/showthread.php?threadid=52873

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Remove Duplicate Pairs(2 Columns)

You could use the concatinate function, and then sort on that column

order_no item_no Concatinate
4 1 41
4 1 41
4 2 42

Then use the code below (though all the words below are NOT keywords, some
are conceptual only to give you the idea):

For r = RowCount To 1 Step -1
Cells(r, 3).Select
celCompare = ActiveCell
If Range.Offset(-1, 0) = celCompare Then
'Delete current row
End If
Next r

Let me know if this helps

"deathswan" wrote:


Hello. I have 2 columns order_no and item_no. Duplicates are allowed in
each column separately, however I would like to remove all duplicate
"pairs" of order_no and item_no. So for instance (order_no, item_no) -
[(1, 4) and (1, 4)] would be deleted, but [(1, 3) and (1, 4)] OR [(1, 3)
and (2, 3)] would be be allowed. Basically my primary key is the
superkey of both order_no and item_no which is why I can't have
duplicates. The 2 columns are right next to each other (order_no is
column C, item_no is column D).

Thanks!
[kyle]


--
deathswan
------------------------------------------------------------------------
deathswan's Profile: http://www.excelforum.com/member.php...o&userid=33060
View this thread: http://www.excelforum.com/showthread...hreadid=528737


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 186
Default Remove Duplicate Pairs(2 Columns)

Hi,
Try this code. It assumes that there are only four columns, A-D, and that
there are no column headers. If there are more columns, change the code in
the row that begins with "Range("A1:D....." to "Range("A1:E....".

Sub DeleteDupes()
Dim Iloop As Integer
Dim Numrows As Integer

'Turn off warnings, etc.
Application.ScreenUpdating = False
Application.DisplayAlerts = False

Numrows = Range("C65536").End(xlUp).Row
Range("A1:D" & Numrows).Select
Selection.Sort Key1:=Range("C1"), Order1:=xlAscending, _
Key2:=Range("D1"), Order2:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
For Iloop = Numrows To 2 Step -1
If Cells(Iloop, "C") & Cells(Iloop, "D") = Cells(Iloop - 1, "C") & _
Cells(Iloop - 1, "D") Then
Rows(Iloop).Delete
End If
Next Iloop

Range("A1").Select

'Turn on warnings, etc.
Application.DisplayAlerts = True
Application.ScreenUpdating = True

End Sub

--
Ken Hudson


"deathswan" wrote:


Hello. I have 2 columns order_no and item_no. Duplicates are allowed in
each column separately, however I would like to remove all duplicate
"pairs" of order_no and item_no. So for instance (order_no, item_no) -
[(1, 4) and (1, 4)] would be deleted, but [(1, 3) and (1, 4)] OR [(1, 3)
and (2, 3)] would be be allowed. Basically my primary key is the
superkey of both order_no and item_no which is why I can't have
duplicates. The 2 columns are right next to each other (order_no is
column C, item_no is column D).

Thanks!
[kyle]


--
deathswan
------------------------------------------------------------------------
deathswan's Profile: http://www.excelforum.com/member.php...o&userid=33060
View this thread: http://www.excelforum.com/showthread...hreadid=528737


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 duplicate rows but keeping all columns DC Excel Worksheet Functions 3 June 10th 09 03:10 AM
Comparing pairs of cells in four columns brents18 Excel Discussion (Misc queries) 7 July 3rd 07 04:10 PM
Sum product of many pairs of columns KeenKiwi Excel Worksheet Functions 3 May 11th 06 12:59 PM
Removing Duplicate Pairs(2 Columns) deathswan Excel Discussion (Misc queries) 3 April 1st 06 05:01 AM
chart with stacked columns in pairs beardedoldness Charts and Charting in Excel 1 January 9th 06 08:50 PM


All times are GMT +1. The time now is 02:58 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"