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:

Sheet 1
Column 1Column 2
Option 1Code 1
Option 2Code 2
Option 3Code 3
Alt 2Code 4
Alt 4Code 5
Alt 5Code 6
Other 1Code 7
Other 2Code 8

<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>
</tbody>

And an example of the second.

Sheet 2
Column 1Column 2Column 3
Origin 1Option 1Code 1
Origin 1Alt 2Code 4
Origin 1Other 1Code 7
Origin 2Option 1Code 1
Origin 2Alt 2Code 4
Origin 2Other 1Code 7
Origin 3Option 2Code 2
Origin 3Alt 4Code 5
Origin 3Other 1Code 7
Origin 4Option 3Code 3
Origin 4Alt 4Code 5
Origin 4Other 1Code 7
Origin 5Option 3Code 3
Origin 5Alt 5Code 6
Origin 5Other 2Code 8

<colgroup><col span="2"><col></colgroup><tbody>
</tbody>

Thank you for your help!
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
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,214,918
Messages
6,122,246
Members
449,075
Latest member
staticfluids

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