PC Review


Reply
Thread Tools Rate Thread

Cut and paste duplicate data

 
 
Dileep Chandran
Guest
Posts: n/a
 
      3rd Jan 2007
Hello,

I have a workbook which contains name, street address, city and state
in columns C to F and date in column G.
Can anybody help me in getting a macro which does the following:

1. Find duplicate, if the entire data (Column C to Column F) is
repeating.
2. Cut and Paste the entire row of duplicates into a new sheet, except
the row which has the latest date in Column G.

Is my question clear?

Any help is greatly appreciated.

-Dileep

 
Reply With Quote
 
 
 
 
Dileep Chandran
Guest
Posts: n/a
 
      3rd Jan 2007

A small addition. The range to look up for duplicate is C2:F1000.

 
Reply With Quote
 
MrScience
Guest
Posts: n/a
 
      3rd Jan 2007
This would handle the deletion of any rows where the Name, Address,
City and State are exactly the same as long as the sheet has been
sorted. I noticed you've received information on how to handle the
sort in a previous post so I didn't include it here.

The cut and paste is pretty involved. Actully, the process of finding
the duplicate and then preparing to paste is pretty simple but you
always have to reference the last used cell in the sheet where you're
going to paste the duplicate.

This code assumes the data has been sorted and then are no blank rows.
As long as that is true, there is no need to worry about the range
reference for the last cell as the code will stop running when it hits
the last row based on the Do loop.

Sub deleteDuplicates()

Dim myName As Variant 'Name column
Set myName = Range("C2")

Do While Not IsEmpty(myName)

Set myAddress = myName.Offset(0, 1)
Set myCity = myName.Offset(0, 2)
Set myState = myName.Offset(0, 3)

Set nextName = myName.Offset(1, 0)
Set nextAddress = myAddress.Offset(1, 0)
Set nextCity = myCity.Offset(1, 0)
Set nextState = myState.Offset(1, 0)

If myName = nextName And _
myAddress = nextAddress And _
myCity = nextCity And _
myState = nextState Then
myName.EntireRow.Delete
End If

Set myName = nextName

Loop


End Sub

 
Reply With Quote
 
Dileep Chandran
Guest
Posts: n/a
 
      3rd Jan 2007
Thank you Mr. Science. But we have to add some code to this.
Instead of deleting the entire row (myName.EntireRow.Delete), we have
to look up Column H for A or B. If there is only one A, then delete the
other column. If both are A, look up Column G and delete the oldest
data (we have to check the latest date).

Thanks in advance for any addition.

-Dileep

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to delete Duplicate Records (1 column), before which, non-duplicate data merged into remaining row EagleOne@discussions.microsoft.com Microsoft Excel Programming 6 20th Aug 2009 02:40 AM
EXCEL PASTE DOES NOT CHANGE DATA - PASTE DOESN'T WORK! robin l Microsoft Excel Worksheet Functions 4 16th Apr 2009 06:52 PM
Duplicate data in subform when I duplicate the main form Lauren CCSD Microsoft Access 3 19th Mar 2008 03:19 PM
Excel cut/Paste Problem: Year changes after data is copy and paste =?Utf-8?B?QXNpZg==?= Microsoft Excel Misc 3 9th Dec 2005 05:16 PM
Duplicate Personal Folders in Folder List and Duplicate Data Files in Email Acco BillBR Microsoft Outlook 2 8th Mar 2004 03:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:11 AM.