Merge duplicate values in row into one column

ilsley_excel

Board Regular
Joined
Mar 5, 2015
Messages
54
Office Version
  1. 2010
Platform
  1. Windows
Hi folks. I have a spreadsheet with a list of clients and their e-mails. However, the way the data comes into me is almost unworkable.

I need to go from this:

Ex1.jpg



To this:

Ex2.jpg



I'm trying to build a macro to consolidate the e-mail address data and make it discrete, but the way I'm doing it seems to be really long-winded.

Any ideas?

Thanks.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi folks. Just bumping this up in the hope that someone might be able to guide me in the right direction!
 
Upvote 0
Hi
what about
VBA Code:
Sub test()
    Cells(1).CurrentRegion.SpecialCells(4).Delete Shift:=xlToLeft
End Sub
 
Upvote 0
Hi
what about
VBA Code:
Sub test()
    Cells(1).CurrentRegion.SpecialCells(4).Delete Shift:=xlToLeft
End Sub

That didn't work unfortunately. It shifts all values to the left and removes the blanks in between.

Thanks for trying however!
 
Upvote 0
Try to attach a mini sheet (XL2BB) to give us something to test.
 
Upvote 0
Try to attach a mini sheet (XL2BB) to give us something to test.

MergeIdenticalRowDataIntoColumns.xlsx
ABCDEFGHIJK
1UniqueIDRefSurnameForenameGroupSubGroupEMAIL1EMAIL2EMAIL3EMAIL4EMAIL5
2ID2432112266JonesAlexG54GA12alex@alex.comalex123@jones.com
3ID2432112266JonesAlexG54GA12alex123@jones.com
4ID2432112266JonesAlexG54GA12alex16@ert.com
5ID6545113442CarterPaulG56GD51paulc@puly.com
6ID5044112278HaleGemmaG55GB13gem@gemma.comgem54@gem.org
7ID5044112278HaleGemmaG55GB13gem@gemma.comgemmah@gem.co.uk
8ID6545113442PoleGeorgeG57GC33georgey@geog.comgeorgey@geog.com
9ID6545113442PoleGeorgeG57GC33geo121@geo.co.uk
Sheet1
 
Upvote 0
Assum data is in sheet1, Output is in Sheet2, from cell A2:
VBA Code:
Option Explicit
Sub test()
Dim lr&, i&, j&, k&, t&, rng, arr(1 To 100000, 1 To 7)
Dim dic As Object
Set dic = CreateObject("Scripting.Dictionary")
With Sheets("Sheet1")
    lr = .Cells(Rows.Count, "A").End(xlUp).Row
    rng = .Range("A2:K" & lr).Value
    For i = 1 To UBound(rng)
        For j = 7 To UBound(rng, 2)
            If Not dic.exists(rng(i, j)) And Not IsEmpty(rng(i, j)) Then
                dic.Add rng(i, j), ""
                k = k + 1: arr(k, 7) = rng(i, j)
                For t = 1 To 6
                    arr(k, t) = rng(i, t)
                Next
            End If
        Next
    Next
End With
With Sheets("Sheet2")
    .Range("A2").Resize(k, 7).Value = arr
End With
End Sub
 
Upvote 0
Solution
Assum data is in sheet1, Output is in Sheet2, from cell A2:
VBA Code:
Option Explicit
Sub test()
Dim lr&, i&, j&, k&, t&, rng, arr(1 To 100000, 1 To 7)
Dim dic As Object
Set dic = CreateObject("Scripting.Dictionary")
With Sheets("Sheet1")
    lr = .Cells(Rows.Count, "A").End(xlUp).Row
    rng = .Range("A2:K" & lr).Value
    For i = 1 To UBound(rng)
        For j = 7 To UBound(rng, 2)
            If Not dic.exists(rng(i, j)) And Not IsEmpty(rng(i, j)) Then
                dic.Add rng(i, j), ""
                k = k + 1: arr(k, 7) = rng(i, j)
                For t = 1 To 6
                    arr(k, t) = rng(i, t)
                Next
            End If
        Next
    Next
End With
With Sheets("Sheet2")
    .Range("A2").Resize(k, 7).Value = arr
End With
End Sub


Wow. That worked perfectly! Hero.

Thank you so much man! Really appreciate it.
 
Upvote 0

Forum statistics

Threads
1,215,005
Messages
6,122,661
Members
449,091
Latest member
peppernaut

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