0

I've been Having a problem with excel regarding matching and merging cells. I have one table that contains some but not all IDs with some data (table1) and I have another that contains all IDs with different data(table2).

I want to match and merge these two tables so that table1 also contains the data that table 2 has, matched by ID.

I do not have enough rep to post picture so I'll try and show what I am struggling with in a code block.

Table 1

F1    Gnr
x12
x25
x37
x63

Table 2

F1    Gnr
x1    y8
x2    y3
x3    y29
etc.  etc.

Desired outcome:

F1     Gnr
x12    y56
x25    y38
x37    y98
x63    y42

This is a simplified version of the problem and I hope it helps to illustrate what I want done. I have tried VLOOKUP and Index and Match but for some reason it WILL NOT work.

edit: Below you find what piece of code I have been using:

=IFERROR(VLOOKUP(Sheet1!A$2;Sheet2!$A$1:$D$50;COLUMN(A1);FALSE);Sheet1!A2)

Here I believe I am looking up the value from sheet1A2 and trying to match that value to the complete table in sheet2. The result I get though is the value of Sheet1!A2 (the iferror value).?

Thanks.

8
  • 1
    Can you explain how y56, y38 etc.. are coming?
    – Harun24hr
    Commented Sep 5, 2018 at 11:26
  • You're on the right track with VLOOKUP / INDEX(MATCH)). Please share what code you've tried, and we can try help you fix it. Commented Sep 5, 2018 at 11:26
  • @Josh Friedlander =IFERROR(VLOOKUP(Sheet1!A$2;Sheet2!$A$1:$D$50;COLUMN(A1);FALSE);Sheet1!A2). Harun, these are just example values. Just know that table 2 contains all F1 values that are in table 1. Commented Sep 5, 2018 at 11:31
  • Can you edit this into the question, and include the result you get from that, and what you'd expect to see instead? Commented Sep 5, 2018 at 11:32
  • @JoshFriedlander Done, I might just not understand what it is I am doing. My brain is fried, I have been looking at this for hours. Commented Sep 5, 2018 at 12:01

2 Answers 2

1

You can use Powerquery (add-in from microsoft for Excel 2013, inbuilt for 2016)

  1. Set up both tables as Excel tables (include headers)

enter image description here

  1. Select cell in one of the tables > Data tab or powerquery (Excel 2013) > from table>

enter image description here

  1. Window that opens > home> close and load to > only create connection>

enter image description here

enter image description here

  1. Repeat for other table

  2. You then have two workbook queries (one for each table)

enter image description here

  1. Data ( or Powerquery) tab > New query > Combine queries > Merge

enter image description here

  1. Select your table 1 (the one to update) then below your table 2, highlight both id columns and then left outer join type

enter image description here

  1. Expand the new table insert to show the merged columns by clicking on the <>

enter image description here

  1. Highlight the two columns in between that aren’t needed and right-click remove columns

enter image description here

  1. Rename the last column as required

enter image description here

  1. Then close and load to new sheet

enter image description here

  1. Observe result

enter image description here

5
  • 1
    I feel like this might be more complicated than the question warranted, but upvoting out of respect for the effort you put in... Commented Sep 5, 2018 at 12:38
  • Wow! Thanks a lot! Will try this! Commented Sep 5, 2018 at 12:49
  • It is useful when dealing with large volumes of data.
    – QHarr
    Commented Sep 5, 2018 at 13:01
  • 1
    Sorry for the late reply but I managed to do it. It actually had to do with the frickin' datatypes... I feel so dumb for not thinking about that. Your guide has been very helpfull anyways so I'll mark this as the answer. Commented Sep 14, 2018 at 11:29
  • Thank you. Another advantage of powerquery is it will warn you about datatypes when loading. You can check the datatypes assigned and also check whether matches were made.
    – QHarr
    Commented Sep 14, 2018 at 11:35
0

Your IFERROR does exactly what you might expect: it receives an error, and returns the "backup" value (in this case, Sheet1!A$2).

The underlying reason for this: your VLOOKUP returns an error!

The reason for this might be because none of the values in Table 1 are present in Table 2. (Or that might just be your example.) If this is true, you might want to consider using fuzzy matching (the last argument in VLOOKUP - either TRUE or FALSE).

It's also possible that there is a mistake in your code. Here's the formula I used for B2:

=VLOOKUP(A2;Sheet2!$A$1:$B$5;2;0)

In general, it's better not to use the IFERROR wrapper until you're sure that the inner code is working.

1
  • It still will not work. I'll try and use the Index Match method one more time. I have no idea why it is not working though, my code seems fine and I have tripple checked if the values that I want to match them on are in both tables. Commented Sep 5, 2018 at 12:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.