If the "Not" function continues when the value * equals * the specified

I am trying to write a script that checks for duplicate values ​​on another sheet, but I cannot get it to work. The line problemwill always execute the If function set to If Notor If. LocationCell does nothing.

I am sure this is an obvious mistake, 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

Also, am I using find correctly? It also does not work.

+1
source share
1 answer

Use On Error Resume Nextwisely.

Do not use On Error Resume Nextfor all code - it will hide all your errors. Use it only when it is really necessary.

On Error Resume Next Shut UP , . , ... ... , !!! (SiddharthRout ©:)

enter image description here

Err.Clear
On Error Resume Next
Set wsDel = Sheets("Matching Contacts")
wsDel.Delete

On Error Resume Next
Set wsDel = Sheets("Matching Contacts")
On Error GoTo 0
If Not wsDel Is Nothing Then wsDel.Delete

line On Error GoTo 0 .


:

1) If Not LocatedCell = "Nothing" Then , "Nothing", .

, .Find ,

If Not LocatedCell = "Nothing" Then 

to

If Not LocatedCell Is Nothing Then

2) With Sheets(mailerSheet).Range("A:A") With mailerSheet.Range("A:A")

3), @SiddharthRout, ,

. Excel , .

,

'With_
   LocatedCell.EntireRow.Copy_
   '.Interior.ColorIndex = 4 'green
'End With

With LocatedCell.EntireRow
     .Interior.ColorIndex = 4 'green
     .Copy
End With

4) , : Select/Active

+12

All Articles