Solved

remove duplicate rows but first copy contents of a cell to the prior row

Posted on 2016-09-12
4
9 Views
Last Modified: 2016-10-29
I have a spreadsheet where column A is Name and column E is email address. If someone has two email addresses they are listed on 2 rows. I need to delete the duplicate row but first I need to move the second email address to a new column in the prior row. How can I do this for hundreds of rows.
0
Comment
Question by:Neal Freed
  • 2
4 Comments
 
LVL 48

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 500 total points
ID: 41795445
Hi,

pls try
Sub macro()
With ActiveSheet.Sort
    .SortFields.Clear
    .SortFields.Add Key:=Range("A1"), _
            SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    .SetRange ActiveSheet.UsedRange
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
End With
For Each c In Range(Range("E2"), Range("E" & Rows.Count).End(xlUp))
    If c.Offset(, -4) = c.Offset(-1, -4) Then
        Cells(c.Row - 1, Columns.Count).End(xlToLeft).Offset(, 1) = c
    End If
Next
ActiveSheet.UsedRange.RemoveDuplicates Columns:=1, Header:=xlYes
End Sub

Open in new window

Regards
0
 

Author Comment

by:Neal Freed
ID: 41795454
Not to seem dense, but how do I try. Here is the file Column I has the Names and Column U has the email addresses
Highline-SE_091416.xls
0
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 41795473
then try
Sub macro()
With ActiveSheet.Sort
    .SortFields.Clear
    .SortFields.Add Key:=Range("D1"), _
            SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    .SetRange ActiveSheet.UsedRange
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
End With
For Idx = Range("I" & Rows.Count).End(xlUp).Row To 2 Step -1
    Set c = Range("I" & Idx)
    If c.Offset(, -5) = c.Offset(-1, -5) Then
        Set Rng = Range(c, Cells(c.Row, Columns.Count).End(xlToLeft))
        Rng.Copy Cells(c.Row - 1, Columns.Count).End(xlToLeft).Offset(, 1)
    End If
Next
ActiveSheet.UsedRange.RemoveDuplicates Columns:=4, Header:=xlYes
End Sub

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
We have come a long way with backup and data protection — from backing up to floppies, external drives, CDs, Blu-ray, flash drives, SSD drives, and now to the cloud.
Viewers will learn the basics of using filtering and sorting in Excel 2013.
Viewers will learn a basic relationship technique in Power Pivot for Excel 2013.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now