merge two rows in excel worksheet where one cell has same content but other cells have different content

Solution 1:

Here's a neat little trick for doing this kind of merge.

  1. Select the value cells in your table, i.e., B2:F5 in your example.
  2. Press F5. Click Special.... Select Blanks and click OK. This will select all the blank cells in the table.
  3. Click inside the formula bar and paste or type the formula below (Do NOT hit Enter):
    =IF($A3=$A2,C3,IF($A1=$A2,C1,""))
    C3 is the cell below the active cell, and (obviously) C1 is the cell above. Adjust the formula to match your table.
  4. Press Ctrl+Enter. This will effectively fill down this formula to all the selected blank cells.

The formula just checks for an entry with the same keyword below it and copies its value if it exists. If no duplicate exists below, then it checks above. If none exists there, the cell remains blank.

Finally, you can copy the table and Paste Special > Values back on top of the table to clear out the formulas but keep the values. Then you can use the Remove Duplicates tool located on the Data ribbon to clean up the table.