Find corresponding record and paste in sheet 2

kettler

New Member
Joined
Aug 9, 2011
Messages
20
Hi All,

Good morning to everyone.

I have a sheet 1 which has the following columns.


Excel Workbook
AB
1Sheet 1*
2Customer agentZone responsible
3**
4JimEU
5TonyEU
6FrancisNA
7JasonSA
8LeslieCN
9JackieROW
Sheet1



How can i write a macro for sheet 2 to search in sheet 1 and if it finds a matching record then paste its corresponding value in sheet 2.


Excel Workbook
DE
1Sheet 2*
2Customer agentZone responsible
3**
4Jim*
5Tony*
6Francis*
7Jason*
8Leslie*
9Jackie*
Sheet2



PS: I dont know why the stars are coming in the blank cells but its not supposed to be there.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Thank you there,

I have read through the article and its excellent for one time use. However my data is changing weekly and my manager wants to press a button instead of copying/cutting/pasting and adjusting (she's very demanding).

so instead of making vlookup im thinking of using a macro. however im not a programing person and donno how to make a macro.

my data is actually 3 columns.

Excel Workbook
ABC
1Customer agentZone responsiblesales
2JimEU6199
3TonyEU2323
4FrancisNA16548
5JasonSA4542
6LeslieCN4656
7JackieROW98588
Sheet1




and she wants to have automatic data pasted in sheet 2 in C2 to C7 in this example.



Excel Workbook
ABC
1Customer agentZone responsiblesales
2JimEU
3TonyEU
4FrancisNA
5JasonSA
6LeslieCN
7JackieROW
Sheet2


Thanks for assisting.
Good day to all.
 
Upvote 0
Try

Code:
Sub LOOK()
Dim LR As Long, i As Long
With Sheets("Sheet2")
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    For i = 2 To LR
        .Range("C" & i).Value = Application.VLookup(.Range("A" & i).Value, Sheets("Sheet1").Columns("A:C"), 3, False)
    Next i
End With
End Sub
 
Upvote 0
Hi Vogg

When i try the code, I get in some cells #REF! and some I get #N/A

Is it Im doing something erroneous? Like this below.


Excel Workbook
L
32#REF!
33#REF!
34#REF!
35#REF!
36#REF!
37#REF!
38#N/A
39#REF!
40#REF!
41#N/A
42#N/A
Testing
 
Upvote 0
My results with your example.


Excel Workbook
ABC
1Customer agentZone responsiblesales
2JimEU6199
3TonyEU2323
4FrancisNA16548
5JasonSA4542
6LeslieCN4656
7JackieROW98588
Sheet2


What is the actual code you are using?
 
Upvote 0
Hello vogg,

this is the code im using:


"Sub testing()
Dim LR As Long, i As Long
With Sheets(""sheet 2"")
LR = .Range(""L"" & Rows.Count).End(xlUp).Row
For i = 3 To LR
.Range(""L"" & i).Value = Application.VLookup(.Range(""O"" & i).Value, Sheets(""sheet 1"").Columns(""D""), 6, False)
Next i
End With
End Sub"


just to explain to be clear:

source tab:
sheet 1
data common to both sheets: in Column D
source data: column F


destination tab:
sheet 2
data common to both sheets: in Column O
data expected to be pasted in: column L
 
Upvote 0
Try

Code:
Sub LOOK()
Dim LR As Long, i As Long
With Sheets("Sheet2")
    LR = .Range("O" & Rows.Count).End(xlUp).Row
    For i = 2 To LR
        .Range("L" & i).Value = Application.VLookup(.Range("O" & i).Value, Sheets("Sheet1").Columns("D:F"), 3, False)
    Next i
End With
End Sub
 
Upvote 0
Hi vogg,

this is fanta-fabulous. thanks to you its working like a charms.

may you have a great day.
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,946
Latest member
JoseDavid

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