Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

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

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 53

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

: Microsoft Office Collaborate for free and online versions of Microsoft  Word, Excel, Powerpoint, OneNote, Onedrive , Email, Calendar etc. In short we can say that Microsoft office is a suite of servers, applications and services developed by  Micr…
Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
Viewers will learn a basic data manipulation technique of unpivoting data in Power Query for Excel 2013 and the importance of using good data. Start with data in a poor structure: Create a table on your data: Unpivot columns: Rename columns: …
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.

885 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