I am trying to write a script which checks for duplicate values in another worksheet, but I cannot get it to work. At line problem
the If function always proceeds, whether set to If Not
or If
. LocatedCell does equal Nothing.
I am sure this is an obvious error but I cannot understand it.
Sub mailer_followuptest()
Application.ScreenUpdating = False
'Remove matching contacts data from last run
Dim wsDel As Worksheet
Application.DisplayAlerts = False
Err.Clear
On Error Resume Next
Set wsDel = Sheets("Matching Contacts")
wsDel.Delete
Dim mailerSheet As Worksheet
Set mailerSheet = Worksheets("Call data")
Set MatchingContacts = Sheets.Add
MatchingContacts.Name = "Matching Contacts"
Dim DesiredEntry As String
Dim CRMContacts As Worksheet
Set CRMContacts = Worksheets("CRM contacts")
CRMContacts.Select
Range("A1").Select
Do
ActiveCell.Offset(1, 0).Select
DesiredEntry = ActiveCell.Value
With Sheets(mailerSheet).Range("A:A")
Dim LocatedCell As Range
Set LocatedCell = .Find(What:=DesiredEntry, SearchOrder:=xlByRows, LookAt:=xlPart)
problem: If Not LocatedCell = "Nothing" Then
'With_
LocatedCell.EntireRow.Copy_
'.Interior.ColorIndex = 4 'green
'End With
MatchingContacts.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveCell.Offset(1, 0).Select
End If
End With
CRMContacts.Select
Loop Until ActiveCell.Value = ""
Application.ScreenUpdating = True
End Sub
Additionally, am I using find correctly? It doesn't appear to be working either.