?
Solved

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

Posted on 2016-09-12
4
Medium Priority
?
17 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 52

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 2000 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 52

Accepted Solution

by:
Rgonzo1971 earned 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 various types of data validation for different data types in Excel 2013.
Viewers will learn how to find and create templates in Excel 2013.

801 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