I am creating a macro that you open while in a client file to search for matches on a Do Not Contact (DNC) Listing. I want the macro to do the following:
1) Open and Sort the Do Not Contact Listing
2) Use a Do...Until Loop to move through the data on the DNC List and an embedded If...Then Statment to check for and highlight any matches in the client file.
Below is the code I have so far. Column P of the DNC List contains the data I want to search by first, then Column D. I keep getting a Compile Error: Variable Not Defined for the MatchCase reference in the If...Then Statement.
I changed the [highlight]highlighted[/highlight] code to the following, but I still receive the same error for the ExactMatch reference:
Any help you can provide is greatly appreciated!!!
Jeff
Initial Code:
Sub DNCList()
'Open Do Not Contact List and Sort
ChDir "G:\"
Workbooks.Open Filename:="G:\Do Not Contact List 07-29-2005.xls"
Cells.Select
Selection.Sort Key1:=Range("P2"), Order1:=xlDescending, Key2:=Range("D2") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom
'Declare IMS Cell Range
Dim rngP As Range
With Worksheets("Do Not Contact List")
Set rngP = .Range(.Range("P2"), .Range("P2").End(xlDown))
End With
ActiveWindow.ActivatePrevious
Do Until rngP Is Nothing
Cells.Select
Selection.Find(What:=rngP, After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
If MatchCase = True Then
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Else: MatchCase = False
End If
Loop
End Sub
New Code:
[highlight]ActiveWindow.ActivatePrevious
Do Until rngP Is Nothing
Cells.Select
ExactMatch = Selection.Find(What:=rngP, After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
If Not ExactMatch is Nothing Then
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Else
ExactMatch = False
End If
Loop[/highlight]
1) Open and Sort the Do Not Contact Listing
2) Use a Do...Until Loop to move through the data on the DNC List and an embedded If...Then Statment to check for and highlight any matches in the client file.
Below is the code I have so far. Column P of the DNC List contains the data I want to search by first, then Column D. I keep getting a Compile Error: Variable Not Defined for the MatchCase reference in the If...Then Statement.
I changed the [highlight]highlighted[/highlight] code to the following, but I still receive the same error for the ExactMatch reference:
Any help you can provide is greatly appreciated!!!
Jeff
Initial Code:
Sub DNCList()
'Open Do Not Contact List and Sort
ChDir "G:\"
Workbooks.Open Filename:="G:\Do Not Contact List 07-29-2005.xls"
Cells.Select
Selection.Sort Key1:=Range("P2"), Order1:=xlDescending, Key2:=Range("D2") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom
'Declare IMS Cell Range
Dim rngP As Range
With Worksheets("Do Not Contact List")
Set rngP = .Range(.Range("P2"), .Range("P2").End(xlDown))
End With
ActiveWindow.ActivatePrevious
Do Until rngP Is Nothing
Cells.Select
Selection.Find(What:=rngP, After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
If MatchCase = True Then
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Else: MatchCase = False
End If
Loop
End Sub
New Code:
[highlight]ActiveWindow.ActivatePrevious
Do Until rngP Is Nothing
Cells.Select
ExactMatch = Selection.Find(What:=rngP, After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
If Not ExactMatch is Nothing Then
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Else
ExactMatch = False
End If
Loop[/highlight]