Paste data from one spreadsheet into another after matches are found

BruceHawk

New Member
Joined
Mar 20, 2016
Messages
12
I thought I had my answer with index match, but it doesn't seem to work for me.

I have two spreadsheets, one with only unique data. The other one has repetitive data. I would like to paste data from Sheet 1, to a column in Sheet 2, when matches are found.

In my example below, the columns that data is being searched and matched for are: In Sheet 1, Column 1. And in Sheet 2, Column 2. If a match is found, the data from Sheet 1, Column 2, would be pasted into Sheet 2, Column 3.

Here's an example of the first spreadsheet:

[TABLE="width: 128"]
<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl65, width: 64"]Sheet 1[/TD]
[TD="width: 64"][/TD]
[/TR]
[TR]
[TD="class: xl65"]Column 1[/TD]
[TD="class: xl65"]Column 2[/TD]
[/TR]
[TR]
[TD]Option 1[/TD]
[TD]Code 1[/TD]
[/TR]
[TR]
[TD]Option 2[/TD]
[TD]Code 2[/TD]
[/TR]
[TR]
[TD]Option 3[/TD]
[TD]Code 3[/TD]
[/TR]
[TR]
[TD]Alt 2[/TD]
[TD]Code 4[/TD]
[/TR]
[TR]
[TD]Alt 4[/TD]
[TD]Code 5[/TD]
[/TR]
[TR]
[TD]Alt 5[/TD]
[TD]Code 6[/TD]
[/TR]
[TR]
[TD]Other 1[/TD]
[TD]Code 7[/TD]
[/TR]
[TR]
[TD]Other 2[/TD]
[TD]Code 8[/TD]
[/TR]
</tbody>[/TABLE]

And an example of the second.

[TABLE="width: 206"]
<colgroup><col span="2"><col></colgroup><tbody>[TR]
[TD]Sheet 2[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Column 1[/TD]
[TD]Column 2[/TD]
[TD]Column 3[/TD]
[/TR]
[TR]
[TD]Origin 1[/TD]
[TD]Option 1[/TD]
[TD]Code 1[/TD]
[/TR]
[TR]
[TD]Origin 1[/TD]
[TD]Alt 2[/TD]
[TD]Code 4[/TD]
[/TR]
[TR]
[TD]Origin 1[/TD]
[TD]Other 1[/TD]
[TD]Code 7[/TD]
[/TR]
[TR]
[TD]Origin 2[/TD]
[TD]Option 1[/TD]
[TD]Code 1[/TD]
[/TR]
[TR]
[TD]Origin 2[/TD]
[TD]Alt 2[/TD]
[TD]Code 4[/TD]
[/TR]
[TR]
[TD]Origin 2[/TD]
[TD]Other 1[/TD]
[TD]Code 7[/TD]
[/TR]
[TR]
[TD]Origin 3[/TD]
[TD]Option 2[/TD]
[TD]Code 2[/TD]
[/TR]
[TR]
[TD]Origin 3[/TD]
[TD]Alt 4[/TD]
[TD]Code 5[/TD]
[/TR]
[TR]
[TD]Origin 3[/TD]
[TD]Other 1[/TD]
[TD]Code 7[/TD]
[/TR]
[TR]
[TD]Origin 4[/TD]
[TD]Option 3[/TD]
[TD]Code 3[/TD]
[/TR]
[TR]
[TD]Origin 4[/TD]
[TD]Alt 4[/TD]
[TD]Code 5[/TD]
[/TR]
[TR]
[TD]Origin 4[/TD]
[TD]Other 1[/TD]
[TD]Code 7[/TD]
[/TR]
[TR]
[TD]Origin 5[/TD]
[TD]Option 3[/TD]
[TD]Code 3[/TD]
[/TR]
[TR]
[TD]Origin 5[/TD]
[TD]Alt 5[/TD]
[TD]Code 6[/TD]
[/TR]
[TR]
[TD]Origin 5[/TD]
[TD]Other 2[/TD]
[TD]Code 8[/TD]
[/TR]
</tbody>[/TABLE]

Thank you for your help!
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
in sheet 2 column 3 first cell =index(sheet 1 column 2, match(sheet 2 column 2 first cell, sheet 1 column 1, 0))
 
Upvote 0
BruceHawk,

Here is a macro solution for you to consider, that is based on your flat text displays.


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Sub BruceHawk()
' hiker95, 08/06/2017, ME1017716
Application.ScreenUpdating = False
Dim w1 As Worksheet, w2 As Worksheet
Dim b As Range, a As Range
Set w1 = Sheets("Sheet1")
Set w2 = Sheets("Sheet2")
With w2
  For Each b In .Range("B1", .Range("B" & Rows.Count).End(xlUp))
    If w1.Cells(1, 1) = b.Value Then
      b.Offset(, 1).Value = w1.Cells(1, 2).Value
    Else
      Set a = w1.Columns(1).Find(b.Value, LookAt:=xlWhole)
      If Not a Is Nothing Then
        b.Offset(, 1).Value = a.Offset(, 1).Value
      End If
    End If
  Next b
  .Activate
  .Columns(3).AutoFit
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm, and, answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.

Then run the BruceHawk macro.
 
Upvote 0
Thanks for helping with the "Part 2" portion as well, that was in a separate thread!!

BruceHawk,

The above quote was from your other thread/post.


Thanks for the feedback.

You are very welcome. Glad I could help.

And, come back anytime.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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