Match data to the name in another sheet

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

Sheet "Data" has

Prod Name in Column A & Prod Extras in B,


Sheet "Extras1"

Product Name in Column A

Product Extras need to go in column D and Onwards

So sheet "Data" Has lot of products and the extras listed for those products in one long list like this (I'm using 3 items as example)

Product Name
Prod Extras
Bread
AB
Ham
AB
Cheese
AB
Cheese
BC
Cheese
CD
Bread
CD
Ham
CD
Bread
BC
Bread
EF
Bread
FG
Ham
FG
Ham
EF
Cheese
FG
sO ALL THE EXTRA ITEMS ARE IN ONE LIST AND THE PRODUCT NAMES ARE REPEATED

<tbody>
</tbody>

What I want is this

Sheet Extra
Bread
AB
BC
CD
EF
FG
Ham
AB
CD
FG
Cheese
AB
BC
CD
FG
so we match the names in each row of "Data" Column A To "Sheet Extra" Column A and insert the extra items into the columns next to each other so I have a list of each item and who it goes to.



<tbody>
</tbody>

Can anyone help me with this please?

Thanks

Tony
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Maybe something along:

Excel 2016 (Windows) 64 bit
ABCDEFGHIJ
1Product NameProd ExtrasABBCCDEFFG
2BreadABBreadABBCCDEFFG
3HamABHamABCDEFFG
4CheeseABCheeseABBCCDFG
5CheeseBC
6CheeseCD
7BreadCD
8HamCD
9BreadBC
10BreadEF
11BreadFG
12HamFG
13HamEF
14CheeseFG
Sheet1
Cell Formulas
RangeFormula
F2{=IFERROR(INDEX($B$2:$B$14,MATCH(1,($A$2:$A$14=$E2)*($B$2:$B$14=F$1),0)),"")}
Press CTRL+SHIFT+ENTER to enter array formulas.

Just add one helper row for the fields in F1 to J1.
Adjust to fit your model.
 
Upvote 0
tonywatsonhelp,

If I understand your correctly, then, here is a macro solution for you to consider.

Sample raw data worksheets:


Excel 2007
AB
1Product NameProd Extras
2BreadAB
3HamAB
4CheeseAB
5CheeseBC
6CheeseCD
7BreadCD
8HamCD
9BreadBC
10BreadEF
11BreadFG
12HamFG
13HamEF
14CheeseFG
15
Data



Excel 2007
ABCDEFGHI
1Bread
2Ham
3Cheese
4
Extra


And, after the macro:


Excel 2007
ABCDEFGHI
1BreadABBCCDEFFG
2HamABCDEFFG
3CheeseABBCCDFG
4
Extra



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 OrganizeData()
' hiker95, 11/30/2016, ME978564
Dim wd As Worksheet, we As Worksheet
Dim c As Range, n As Range, e As Range
Dim nr As Long, lr As Long
Application.ScreenUpdating = False
Set wd = Sheets("Data")
Set we = Sheets("Extra")
With we
  .Rows(1).Insert
  wd.Columns(2).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=we.Columns(4), Unique:=True
  Application.CutCopyMode = False
  lr = .Cells(Rows.Count, 4).End(xlUp).Row
  .Range("D2:D" & lr).Sort key1:=.Range("D2"), order1:=1
  .Range("D1").Resize(, lr - 1).Value = Application.Transpose(.Range("D2:D" & lr))
  .Range("D2:D" & lr).ClearContents
End With
With wd
  For Each c In .Range("A2", .Range("A" & Rows.Count).End(xlUp))
    Set n = we.Columns(1).Find(c.Value, LookAt:=xlWhole)
    If n Is Nothing Then
      nr = we.Cells(we.Rows.Count, "A").End(xlUp).Row + 1
      we.Cells(1, nr).Value = c.Value
      Set e = we.Rows(1).Find(c.Offset(, 1).Value, LookAt:=xlWhole)
      If Not e Is Nothing Then
        we.Cells(nr, e.Column).Value = c.Offset(, 1).Value
      End If
    ElseIf Not n Is Nothing Then
      Set e = we.Rows(1).Find(c.Offset(, 1).Value, LookAt:=xlWhole)
      we.Cells(n.Row, e.Column).Value = c.Offset(, 1).Value
    End If
  Next c
End With
With we
  .Rows(1).Delete
  .UsedRange.Columns.AutoFit
  .Activate
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 OrganizeData macro.
 
Upvote 0
Cyril, thank you, but I think there might be a little to much data this time to use a formula, I will however be able to use your example on another idea I had so thank you.

Hiker95, thank you, this is what I was looking for, so thank you very much.

Tony
 
Upvote 0
Hiker95, thank you, this is what I was looking for, so thank you very much.

tonywatsonhelp,

Thanks for the feedback.

You are very welcome. Glad I could help.

And, come back anytime.
 
Upvote 0

Forum statistics

Threads
1,214,821
Messages
6,121,762
Members
449,048
Latest member
excelknuckles

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