Update Cell Value Based on Match to Outside Workbook

Bill Reader

New Member
Joined
Apr 8, 2013
Messages
3
Hi, friends. I have a list of 10K emails in my active workbook, where many duplicates exist. In another workbook I have a list of bad email addresses. I'm looking for a macro that would help me update the Status column in my active workbook with the word "bad" if there is a match:

"If the email address listed in Column A of my active Workbook1 matches the email address listed in Column A of Workbook2, then place "bad" in Column B of Workbook 1."

Can anyone help with this? Thanks!
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I haven't tested this so you'll have to report back with any errors, and the lines they occur on. Sorry!

Code:
Option Explicit

Sub MatchBads()

Dim wbCurrent As Workbook
Dim wbExternal As Workbook
Dim rng As Range
Dim cel As Range
Dim rngResult As Range
Set wbCurrent = ThisWorkbook
Set wbExternal = Workbooks.Open(Filename:="c:\yourPath\goes\here.xlsm")

With wbCurrent.Sheets(1)

Set rng = .Range("A1:A" & Range("A" & .Rows.Count).End(xlUp).Row)

For Each cel In rng

   Set rngResult = (wbExternal.Sheets(1).Range("A:A").Find(cel.Text, LookAt:=xlWhole)) 
    
    If Not rngResult Is Nothing Then
    
        cel.Offset(, 1) = rngResult
        
    End If
    
Next cel

End with

wbExternal.Close False
Set wbExternal = Nothing

End Sub
 
Last edited:
Upvote 0
Thank you for your quick reply! In red is where it first error occurs. I don't think I'm listing my external workbook/file correctly. I suspect the other place I entered my external workbook/file (toward the end) is wrong too. Thanks for any suggestions.

Sub MatchBads()
Dim wbCurrent As Workbook
Dim wbExternal As Workbook
Dim rng As Range
Dim cel As Range
Dim rngResult As Range
Set wbCurrent = ThisWorkbook
Set wbExternal = Workbooks.Open(Filename:="c:\users\breader\desktop\test1\NTHClientContacts.xlsx")
With wbCurrent.Sheets(1)
Set rng = .Range("g1:g" & Range("g" & .Rows.Count).End(xlUp).Row)
For Each cel In rng
Set rngResult = (c:\users\breader\desktop\test1\HardBounces.Sheets(1).Range("A:A").Find(rng.Text, LookAt:=xlWhole))

If Not rngResult Is Nothing Then

rng.Offset(, 1) = rngResult

End If

Next cel
End With
c:\users\breader\desktop\test1\HardBounces.Close False
Set wbExternal = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,396
Messages
6,055,163
Members
444,767
Latest member
bryandaniel5

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top