Solved

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

Posted on 2016-09-12
4
12 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 49

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 49

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

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.
: 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…
Viewers will learn how to find and create templates in Excel 2013.
Viewers will learn the basics of the new Quick Analysis feature in Excel 2013.

803 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