Cozmo1
06-03-2008, 12:06 PM
Hi guys! In my quest for an answer to my issue I came upon your site. Seems like the most promising forum to go to regarding VB issues. I hope my question is an easy one.
I created a macro to copy an entry in cell C1, search for it in column A, delete it, shift cells up, go back to C1, delete its entry, shift cells up and do the process over again. I have a list of 1700+ entries in column A (primary). I have a list of 600+ entries in column C that is a list of disabled users. I would like to delete the disabled users from column A, which would, in turn, effectively truncate it down to about 1,100+ entries in column A. All entries in column C are unique. If it'll help, here's the code within the macro:
Sub CleanUp()
'
' CleanUp Macro
' Referencing column C, find duplicates in column A and delete them.
'
'
Dim LastColumn As Integer
Dim LastRow As Long
Dim LastCell As Range
If WorksheetFunction.CountA(Cells) > 0 Then
ActiveCell.Offset(0, 2).Range("A1").Select
Selection.Copy
ActiveCell.Offset(0, -2).Range("A1").Select
LastRow = Cells.Find(What:="SAMPLE", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
ActiveCell.Offset(-6, 2).Range("A1").Select
Selection.Delete Shift:=xlUp
ActiveCell.Offset(0, -2).Range("A1").Select
End If
End Sub
I thought it might be an issue with the Find code (highlighted in blue above), but I don't know if there's a way to tell it to copy and search for whatever it had just copied from the cell entry. Do you guys know of a way? Or could there be an even better way to do this?
Thank you very much for your time :)
I created a macro to copy an entry in cell C1, search for it in column A, delete it, shift cells up, go back to C1, delete its entry, shift cells up and do the process over again. I have a list of 1700+ entries in column A (primary). I have a list of 600+ entries in column C that is a list of disabled users. I would like to delete the disabled users from column A, which would, in turn, effectively truncate it down to about 1,100+ entries in column A. All entries in column C are unique. If it'll help, here's the code within the macro:
Sub CleanUp()
'
' CleanUp Macro
' Referencing column C, find duplicates in column A and delete them.
'
'
Dim LastColumn As Integer
Dim LastRow As Long
Dim LastCell As Range
If WorksheetFunction.CountA(Cells) > 0 Then
ActiveCell.Offset(0, 2).Range("A1").Select
Selection.Copy
ActiveCell.Offset(0, -2).Range("A1").Select
LastRow = Cells.Find(What:="SAMPLE", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
ActiveCell.Offset(-6, 2).Range("A1").Select
Selection.Delete Shift:=xlUp
ActiveCell.Offset(0, -2).Range("A1").Select
End If
End Sub
I thought it might be an issue with the Find code (highlighted in blue above), but I don't know if there's a way to tell it to copy and search for whatever it had just copied from the cell entry. Do you guys know of a way? Or could there be an even better way to do this?
Thank you very much for your time :)