Find the 2 column values and search in reverse in same 2 columns

Important Notice


Please note that on 14th December 2023 users will experience an expected outage whilst we make upgrades to our network. We anticipate this process may take a couple of hours and so we apologise in advance for any inconvenience.

  • Hello,


    Can anyone help me how to to check in vba the values for two columns (NameA and NameB) and check it on reverse columns (NameB and NameA) and highlights the duplicates if found


    [TABLE="width: 200"]

    [tr]


    [td]

    Item

    [/td]


    [td]

    NameA

    [/td]


    [td]

    TerminalA

    [/td]


    [td]

    NameB

    [/td]


    [td]

    TerminalB

    [/td]


    [td]

    Remarks

    [/td]


    [/tr]


    [tr]


    [td]

    1

    [/td]


    [td]

    2000

    [/td]


    [td]

    XXX1

    [/td]


    [td]

    2001

    [/td]


    [td]

    XXX2

    [/td]


    [td]

    Duplicate@item4

    [/td]


    [/tr]


    [tr]


    [td]

    2

    [/td]


    [td]

    2002

    [/td]


    [td]

    YYYA

    [/td]


    [td]

    2003

    [/td]


    [td]

    YYYB

    [/td]


    [td]

    Duplicate@item6

    [/td]


    [/tr]


    [tr]


    [td]

    3

    [/td]


    [td]

    XYZ22

    [/td]


    [td]

    ABCA

    [/td]


    [td]

    XYZ11

    [/td]


    [td]

    ABCB

    [/td]


    [td]

    no Duplicate

    [/td]


    [/tr]


    [tr]


    [td]

    4

    [/td]


    [td]

    2001

    [/td]


    [td]

    XXX2

    [/td]


    [td]

    2000

    [/td]


    [td]

    XXX1

    [/td]


    [td]

    Duplicate@item1

    [/td]


    [/tr]


    [tr]


    [td]

    5

    [/td]


    [td]

    2003

    [/td]


    [td]

    YYYB

    [/td]


    [td]

    2002

    [/td]


    [td]

    YYYA

    [/td]


    [td]

    Duplicate@item2

    [/td]


    [/tr]


    [tr]


    [td]

    6

    [/td]


    [td]

    2000

    [/td]


    [td]

    ZZZA

    [/td]


    [td]

    2002

    [/td]


    [td]

    ZZZB

    [/td]


    [td]

    no Duplicate

    [/td]


    [/tr]


    [/TABLE]


    br,


    Ivan

  • Re: Find the 2 column values and search in reverse in same 2 columns


    Try this code:


  • Re: Find the 2 column values and search in reverse in same 2 columns


    Thanks a lot shknbk2.


    I tested it on some other data, it gives an error... some was found "no duplicates" but when i check it has duplicates, and the remarks has found the duplicate.
    Please see below table results.


    [TABLE="width: 421"]

    [tr]


    [td]

    Item

    [/td]


    [td]

    NameA

    [/td]


    [td]

    TerminalA

    [/td]


    [td]

    NameB

    [/td]


    [td]

    TerminalB

    [/td]


    [td]

    Remarks

    [/td]


    [/tr]


    [tr]


    [TD="align: right"]1[/TD]

    [td]

    3000

    [/td]


    [td]

    W07B

    [/td]


    [td]

    4884

    [/td]


    [td]

    W07A

    [/td]


    [td]

    no Duplicate

    [/td]


    [/tr]


    [tr]


    [TD="align: right"]159[/TD]

    [td]

    4884

    [/td]


    [td]

    W07A

    [/td]


    [td]

    3000

    [/td]


    [td]

    W07B

    [/td]


    [td]

    Duplicate@item1

    [/td]


    [/tr]


    [tr]


    [TD="align: right"]79[/TD]

    [td]

    4841

    [/td]


    [td]

    B20B

    [/td]


    [td]

    4840

    [/td]


    [td]

    B20A

    [/td]


    [td]

    Duplicate@item70

    [/td]


    [/tr]


    [tr]


    [TD="align: right"]70[/TD]

    [td]

    4840

    [/td]


    [td]

    B20A

    [/td]


    [td]

    4841

    [/td]


    [td]

    B20B

    [/td]


    [td]

    no Duplicate

    [/td]


    [/tr]


    [/TABLE]


    What if i wanted to transfer the whole rows for duplicates to another sheet and remain the unique rows only.


    br,

  • Re: Find the 2 column values and search in reverse in same 2 columns


    Upload the spreadsheet that causes these errors. The only way for me to find out is to use your data. Also include in the uploaded workbook additional sheets showing what you want the results to look like after transferring the rows.

  • Re: Find the 2 column values and search in reverse in same 2 columns


    Quote

    I tested it on some other data, it gives an error... some was found "no duplicates" but when i check it has duplicates, and the remarks has found the duplicate.
    Please see below table results.


    Give an example or two of which ones are wrong. I wrote a program also and tested it against your attached file in post #5 along with shknbk2's code. I get identical results. So give an example of one that's a duplicate that comes up as not a duplicate.

    Bruce :cool:

  • Re: Find the 2 column values and search in reverse in same 2 columns


    hi skywiter,


    as per my attached file and shknbk2's code, after i run the code, please filter @ colum TerminalB.


    Here it shows no Duplicate @ row20 but it shows Duplicate@item20 @ row 479, same with the other one.


    The duplicate should not show from Col NameA & TerminalA to Col NameB & TerminalB.


    [TABLE="width: 421"]

    [tr]


    [td]

    Item

    [/td]


    [td]

    NameA

    [/td]


    [td]

    TerminalA

    [/td]


    [td]

    NameB

    [/td]


    [td]

    TerminalB

    [/td]


    [td]

    Remarks

    [/td]


    [/tr]


    [tr]


    [TD="align: right"]20[/TD]

    [td]

    2002

    [/td]


    [td]

    D7AB

    [/td]


    [td]

    2191

    [/td]


    [td]

    D7AA

    [/td]


    [td]

    no Duplicate

    [/td]


    [/tr]


    [tr]


    [TD="align: right"]479[/TD]

    [td]

    2191

    [/td]


    [td]

    D7AA

    [/td]


    [td]

    2002

    [/td]


    [td]

    D7AB

    [/td]


    [td]

    Duplicate@item20

    [/td]


    [/tr]


    [tr]


    [TD="align: right"]1023[/TD]

    [td]

    2326

    [/td]


    [td]

    DLOB

    [/td]


    [td]

    4178

    [/td]


    [td]

    DLOA

    [/td]


    [td]

    no Duplicate

    [/td]


    [/tr]


    [tr]


    [TD="align: right"]1027[/TD]

    [td]

    4178

    [/td]


    [td]

    DLOA

    [/td]


    [td]

    2326

    [/td]


    [td]

    DLOB

    [/td]


    [td]

    Duplicate@item1023

    [/td]


    [/tr]


    [/TABLE]


    br,

  • Re: Find the 2 column values and search in reverse in same 2 columns


    Okay, try mine.
    It's slower, but I seem to get the right answers for those two items.


    Bruce :cool:

  • Re: Find the 2 column values and search in reverse in same 2 columns


    Thanks a lot, skywriter, it works perfectly fine.


    What if i wanted to transfer/separate all duplicated rows to sheet2 and remain only the unique values on sheet1?


    br,

  • Re: Find the 2 column values and search in reverse in same 2 columns


    Try this on a copy. :cool:


    Bruce :cool:

  • Re: Find the 2 column values and search in reverse in same 2 columns


    Thanks again, skywriter.


    What i mean is, @ sheet 1


    [TABLE="width: 427"]

    [tr]


    [td]

    Item

    [/td]


    [td]

    NameA

    [/td]


    [td]

    TerminalA

    [/td]


    [td]

    NameB

    [/td]


    [td]

    TerminalB

    [/td]


    [td]

    Remarks

    [/td]


    [/tr]


    [tr]


    [TD="align: right"]352 [/TD]

    [td]

    2137

    [/td]


    [td]

    DKJB

    [/td]


    [td]

    1

    [/td]


    [td]

    DKJA

    [/td]


    [td]

    Duplicate@item 1

    [/td]


    [/tr]


    [tr]


    [TD="align: right"]8[/TD]

    [td]

    58

    [/td]


    [td]

    DKLA

    [/td]


    [td][/td]


    [td]

    DKLB

    [/td]


    [td]

    No duplicate

    [/td]


    [/tr]


    [/TABLE]


    Then @ sheet 2
    [TABLE="width: 427"]

    [tr]


    [td]

    Item

    [/td]


    [td]

    NameA

    [/td]


    [td]

    TerminalA

    [/td]


    [td]

    NameB

    [/td]


    [td]

    TerminalB

    [/td]


    [td]

    Remarks

    [/td]


    [/tr]


    [tr]


    [TD="align: right"]1[/TD]

    [td]

    1

    [/td]


    [td]

    DKJA

    [/td]


    [td]

    2137

    [/td]


    [td]

    DKJB

    [/td]


    [td]

    Duplicate@item 352

    [/td]


    [/tr]


    [/TABLE]


    br,

  • Re: Find the 2 column values and search in reverse in same 2 columns


    You know, you are really complicating things by not just stating what you wanted from the beginning. You said you just wanted to find some things, now you want to do something more complicated, so I feel like I've completely wasted my time writing code for you.


    This is not how I would have written this code had I known what you wanted.


    My suggestion would be to start a new thread.

    Bruce :cool:

  • Re: Find the 2 column values and search in reverse in same 2 columns


    Thanks skywriter..


    I really appreciated your code.


    Have a nice day! :)

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!