Solved

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

Posted on 2016-09-12
4
15 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 51

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 51

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Viewers will learn how to find and create templates in Excel 2013.
Viewers will learn the basics of formula auditing in Excel 2013.

705 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