Select value, search down a column for match

rtpeter

New Member
Joined
Mar 28, 2012
Messages
3
I'm trying to "create a macro" to copy a value (from Column-A), search down Column-C, find matching email and then paste it in Column-B of the same worksheet. Column-C remains unchanged, as it's simply a source of email addresses for possible matches. If no match is found, process continues down Column-A.

BEFORE:
Name,Email,Source_Emails,
Homer.Simpson,,Homer.Simpson@yahoo.com,
Marge.Simpson,,Marge.Simpson@hotmail.com,
Bart.Simpson,,Maggie.Simpson@yahoo.com,
Lisa.Simpson,,Mary.Bailey@yahoo.com,
Maggie.Simpson,,Jasper.Beardly@hotmail.com,

AFTER:
Name,Email,Source_Emails,
Homer.Simpson,Homer.Simpson@yahoo.com,Homer.Simpson@yahoo.com,
Marge.Simpson,Marge.Simpson@hotmail.com,Marge.Simpson@hotmail.com,
Bart.Simpson,,Maggie.Simpson@yahoo.com,
Lisa.Simpson,,Mary.Bailey@yahoo.com,
Maggie.Simpson,Maggie.Simpson@yahoo.com,Jasper.Beardly@hotmail.com,
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi,

Can you use a formula or do you need to use a macro?

Perhaps try this formula and drag down (for Excel 2007+):
Excel Workbook
ABC
1NameEmailSource_Emails
2Homer.SimpsonHomer.Simpson@yahoo.comHomer.Simpson@yahoo.com
3Marge.SimpsonMarge.Simpson@hotmail.comMarge.Simpson@hotmail.com
4Bart.SimpsonMaggie.Simpson@yahoo.com
5Lisa.SimpsonMary.Bailey@yahoo.com
6Maggie.SimpsonMaggie.Simpson@yahoo.comJasper.Beardly@hotmail.com
Sheet2
Excel 2010
Cell Formulas
RangeFormula
B2=IFERROR(INDEX(C$2:C$6,MATCH(A2,INDEX(LEFT(C$2:C$6,FIND("@",C$2:C$6)-1),0),0)),"")
Or for earlier versions maybe try:

=IF(ISERROR(MATCH(A2,INDEX(LEFT(C$2:C$6,FIND("@",C$2:C$6)-1),0),0)),"",INDEX(C$2:C$6,MATCH(A2,INDEX(LEFT(C$2:C$6,FIND("@",C$2:C$6)-1),0),0)))
 
Last edited:
Upvote 0
And if you plan to use vba instead of the formula approach, perhaps something like this.
Code:
Sub TheSimpsonsMacro()
Dim RngA As Range, RngC As Range, LstRw As Long
LstRw = Cells(Rows.Count, "A").End(xlUp).Row
For Each RngA In Range("A1:A" & LstRw)
  For Each RngC In Range("C1:C" & LstRw)
    If RngA.Value = Left(RngC.Value, Len(RngA.Value)) Then _
      RngA(, 2).Value = RngC.Value
  Next RngC
Next RngA
End Sub

Hope it helps.
 
Upvote 0
CircledChicken, HalfAce,

Thank you both so much for your help. Both suggestions worked great on my example file, but the formula also worked extremely well on my real data. Would either of you recommend a good macros and formulas book for an occasional user?

Thank you again for such quick and thorough responses!
V/R Richard
 
Upvote 0
Your welcome and thanks for your feedback.

I'm not sure about books but here are a few of the online resources that I use and have helped me a lot:

Videos for all levels and great explanation of everything (including some VBA I think):
http://www.youtube.com/user/ExcelIsFun
http://www.youtube.com/user/bjele123
http://www.youtube.com/user/contextures

Websites:
http://www.cpearson.com/Excel/MainPage.aspx
http://contextures.com/tiptech.html
http://peltiertech.com/
http://www.ozgrid.com

I know there are many, many more great ones but I can't list them all...
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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