简体   繁体   中英

Remove duplicates from column B based on values in column A in Microsoft Excel

I was removing duplicates easily in column A but now my values have exceeded A1048576, now I have no option but to use column B, but now I cannot remove duplicate values found in column B from the column A. How can I do it? How to treat columns A, B, C etc as one/single column.

Suppose my column A and B has these values

A   B

a   k
b   l
c   a
d   f
e   r
f   
g   

As you can see, column B has values a and f which also exists in column A, so I want to remove a and f.

Thanks for your help and cooperation in this regard.

You can use VBA to loop through all of the cells although it may take a while to run due to the volume of cells in your data. Something like this would work:

Sub RemoveDuplicates()

    Dim rng As Range
    Dim x as Long

    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False

    Set rng = ThisWorkbook.Sheets("SheetName").Range("A2:C1048576")

    For x = rng.Cells.Count To 1 Step -1
        If WorksheetFunction.CountIf(rng, rng(x)) > 1 Then
            rng(x).Delete xlShiftUp
        End If
    Next x

    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True

End Sub

The above subroutine would convert this:

A   B

a   d
a   d
a   e
b   e
b   f
c   
c  

Into this:

A   B

a   d
b   e
c   f

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM