PDA

View Full Version : How to delete whatever appear in column A, from column B



jphleung
09-16-2008, 08:49 PM
Hi all,

I currently would like to do the following: there are two columns of numbers (it can be up to 25000 numbers in a column). Name the two columns ColA and ColB. I would like to delete the numbers that have appeared in ColA from ColB.

E.g. ColA: 2,4,6,8
ColB: 1,2,3,4,5,6,7,8,9,0

I would like to have the code to return ColB as 1,3,5,7,9,0. I have found a few code for similar problem, but they dont really solve mine. Please help me the code, I am very appreciate about it.

Jeff

mikerickson
09-16-2008, 09:49 PM
Dim colA As Range
Dim colB As Range
With ThisWorkbook.Sheets("Sheet1")
With Range("A:A")
Set colA = Range(.Cells(1, 1), .Cells(.Rows.Count, 1).End(xlUp))
End With
With Range("B:B")
Set colB = Range(.Cells(1, 1), .Cells(.Rows.Count, 1).End(xlUp))
End With
End With

With colB.Parent
With .Cells(colB.Row, .UsedRange.Column + .UsedRange.Columns.Count + 1).Resize(colB.Rows.Count, 1)
.FormulaR1C1 = "=MATCH(RC" & colB.Column & "," & colA.Address(, , xlR1C1) & ",0)"
On Error Resume Next
Application.Intersect(.SpecialCells(xlCellTypeFormulas, xlNumbers).EntireRow, colB).Delete shift:=xlUp
On Error GoTo 0
.EntireColumn.Delete
End With
End With

jphleung
09-17-2008, 02:17 PM
Thank you, it works well