View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default Deleting cells in a column ref a different column

Daminc,

Try the macro below. Assumes that your header is in row 1, and there are no blanks in column A.

HTH,
Bernie
MS Excel MVP


Sub DeleteRepeatsInColumnABasedOnColumnC()
Dim myRow As Long
With Application
.ScreenUpdating = False
.EnableEvents = False
End With

myRow = Cells(Rows.Count, 1).End(xlUp).Row
Range("A1").EntireColumn.Insert
Range("A1").Value = "Flag"
Range("A2").Formula = _
"=IF(COUNTIF(D:D,B2)0,""Delete"","""")"
Range("A2").AutoFill Destination:=Range("A2:A" & myRow)
Range("A:B").Sort key1:=Range("A2"), order1:=xlAscending, Header:=xlYes
With Range("A:A")
.AutoFilter Field:=1, Criteria1:="Delete"
.SpecialCells(xlCellTypeVisible).Areas(2).Select
Selection.Offset(0, 1).Select
Selection.Delete Shift:=xlUp
.EntireColumn.Delete
End With

With Application
.ScreenUpdating = True
.EnableEvents = True
End With

End Sub


"Daminc" wrote in message
...

I've tried searching for a solution without success (probably using the
wrong key phrases)

I have a numbers in column A (4434)
And I have numbers in column C (389)

I wish for any number in column C that is duplicated in column A to be
deleted from column A.

I've tried messing around with:

Sub rem_dup_test()
'
' rem_dup_test Macro
' Macro recorded 15/12/2005 by PreeceJ
'

'
Application.ScreenUpdating = False


Dim lastrow As Long, i As Long, l As Long
Dim DupNum As Range, MainColumn As Range

lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To lastrow
For l = 1 To lastrow

Set DupNum = Cells(i, "C")
Set MainColumn = Cells(i, "A")
If MainColumn = DupNum Then Selection.Delete Shift:=xlUp
Next l
Next i

End Sub

but it doesn't even come close :(

Any advice please?


--
Daminc
------------------------------------------------------------------------
Daminc's Profile: http://www.excelforum.com/member.php...o&userid=27074
View this thread: http://www.excelforum.com/showthread...hreadid=493823