Macro to Summarize Address Data

Alex0013

Board Regular
Joined
Jul 23, 2014
Messages
158
Office Version
  1. 365
Platform
  1. Windows
Hello,

I'm looking for help in creating a macro to summarize a member database by Address. This is to get our mailing address list from our member database.

Any help on how I can accomplish this would be greatly appreciated!

Example Data (Sheet 1):
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]First Name[/TD]
[TD]Last Name[/TD]
[TD]Address[/TD]
[TD]City[/TD]
[TD]State[/TD]
[TD]ZIP[/TD]
[/TR]
[TR]
[TD]Alex[/TD]
[TD]Johnson[/TD]
[TD]123 Broadway St[/TD]
[TD]Santa Clara[/TD]
[TD]IL[/TD]
[TD]54687[/TD]
[/TR]
[TR]
[TD]Leah[/TD]
[TD]Johnson[/TD]
[TD]123 Broadway St[/TD]
[TD]Santa Clara[/TD]
[TD]IL[/TD]
[TD]54687[/TD]
[/TR]
[TR]
[TD]Jason[/TD]
[TD]Mendoza[/TD]
[TD]765 State St[/TD]
[TD]Dorson[/TD]
[TD]MS[/TD]
[TD]87456[/TD]
[/TR]
</tbody>[/TABLE]

Desired Result (Sheet 2):
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Names[/TD]
[TD]Address[/TD]
[TD]City[/TD]
[TD]State[/TD]
[TD]ZIP[/TD]
[/TR]
[TR]
[TD]Alex & Leah Johnson[/TD]
[TD]123 Broadway St[/TD]
[TD]Santa Clara[/TD]
[TD]IL[/TD]
[TD]54687[/TD]
[/TR]
[TR]
[TD]Jason Mendoza[/TD]
[TD]765 State St[/TD]
[TD]Dorson[/TD]
[TD]MS[/TD]
[TD]87456[/TD]
[/TR]
</tbody>[/TABLE]


Basically, I want the names concatenated, and duplicates removed on unique combination of Address+City+State+ZIP

Anyone have any ideas on how I might be able to achieve this?

Thanks!
Alex
(Office 365 Version 1902, Windows 10)
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
See next code
Code:
Option Explicit
Sub Treat()
Dim ObjDic   As Object
Set ObjDic = CreateObject("Scripting.Dictionary")
Dim DelRg  As Range
Dim I  As Integer, LR  As Integer
Dim WkK, WkI
    LR = Cells(Rows.Count, 1).End(3).Row
    Set DelRg = Cells(LR + 1, 1)
    For I = 2 To LR
        WkK = Cells(I, 2) & Cells(I, 3) & Cells(I, 4) & Cells(I, 5)
        If (ObjDic.exists(WkK)) Then
            Set DelRg = Union(DelRg, Cells(I, 1))
            WkI = ObjDic.Item(WkK)
            Cells(WkI, 1) = Cells(WkI, 1) & " & " & Cells(I, 1)
        Else
            ObjDic(WkK) = I
        End If
    Next I
    DelRg.EntireRow.Delete
End Sub
 
Upvote 0
Old fashioned way

Code:
Sub t()
Dim sh1 As Worksheet, sh2 As Worksheet, c As Range, lr As Long, fn As Range
Set sh1 = Sheets(1) 'Edit sheet name
Set sh2 = Sheets(2) 'Edit sheet name
lr = sh1.Cells.Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row
    With sh1
        .Range("C1:C" & lr).AdvancedFilter xlFilterCopy, , .Cells(lr + 2, 1), True
        For Each c In .Cells(lr + 2, 1).CurrentRegion.Offset(1)
            If c <> "" Then
                Set fn = .Range("C1:C" & lr).Find(c.Value, , xlValues)
                    If Not fn Is Nothing Then
                        If fn.Value = fn.Offset(1).Value And fn.Offset(, 3).Value = fn.Offset(1, 3).Value And _
                        fn.Offset(, -1).Value = fn.Offset(1, -1).Value Then
                            sh2.Cells(Rows.Count, 1).End(xlUp)(2) = _
                            fn.Offset(, -2).Value & " ""&"" " & fn.Offset(1, -2).Value
                            sh2.Cells(Rows.Count, 1).End(xlUp).Offset(, 1).Resize(, 5) = _
                            fn.Offset(, -1).Resize(, 5).Value
                        ElseIf fn.Value = fn.Offset(1).Value And fn.Offset(, 3).Value = fn.Offset(1, 3).Value And _
                        fn.Offset(, 1).Value <> fn.Offset(1, -1).Value Then
                            sh2.Cells(Rows.Count, 1).End(xlUp)(2) = _
                            fn.Offset(, -2).Value & vbLf & fn.Offset(1, -2).Value
                            sh2.Cells(Rows.Count, 1).End(xlUp).Offset(, 1) = _
                            fn.Offset(, -1).Value & vbLf & fn.Offset(1, -1).Value
                            sh2.Cells(Rows.Count, 1).End(xlUp).Offset(, 2).Resize(, 4) = _
                            fn.Resize(, 4).Value
                        Else
                            sh2.Cells(Rows.Count, 1).End(xlUp)(2).Resize(, 6) = fn.Offset(, -2).Resize(, 6).Value
                        End If
                    End If
            End If
        Next
        .Cells(lr + 2, 1).CurrentRegion.ClearContents
    End With
End Sub
 
Upvote 0
Thank you both so much for your quick and accurate responses! Both worked perfectly in different ways!
 
Upvote 0
Power Query solution for kicks.

Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Group = Table.Group(Source, {"Last Name"}, {{"Count", each _, type table}}),
    FNCombo = Table.AddColumn(Group, "Custom", each Text.Combine(Table.Column([Count],"First Name"), " & ") & " " & [Last Name]),
    Remove = Table.RemoveColumns(FNCombo,{"Last Name"}),
    Reorder = Table.ReorderColumns(Remove,{"Custom", "Count"}),
    Expand = Table.ExpandTableColumn(Reorder, "Count", {"Address", "City", "State", "ZIP"}, {"Address", "City", "State", "ZIP"}),
    NoDupes = Table.Distinct(Expand, {"Custom"}),
    Rename = Table.RenameColumns(NoDupes,{{"Custom", "Names"}})
in
    Rename
 
Upvote 0
Thank you both so much for your quick and accurate responses! Both worked perfectly in different ways!

You're welcome and thanks for the feedback,
Regards, JLG
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

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