PC Review


Reply
Thread Tools Rate Thread

Deleting duplicated rows based on data in two columns

 
 
Monk
Guest
Posts: n/a
 
      17th Nov 2009
I have a range of data in cells A1:K1000 and some of the row data in that
range has been partially duplicated. What I would like to do is to delete
the duplicated row if the cell values in column A are the same as well as the
data in Column E.

For example:
If cell A1 (Smith) and A2 (Smith) are the same and cells E1 (Microsoft) and
E2 (Microsoft) are the same, delete row 2. However If cell A1 (Smith) and A2
(Smith) are the same and cells E1 (Microsoft) and E2 (Apple) are different,
then this is not a duplicate so it should not be deleted.

Any assistance would be appreciated.
 
Reply With Quote
 
 
 
 
JBeaucaire
Guest
Posts: n/a
 
      17th Nov 2009
Try this:

========
Sub DeleteDupes()
'JBeaucaire (11/16/2009)
Dim LR As Long, i As Long
Application.ScreenUpdating = False

LR = Range("A" & Rows.Count).End(xlUp).Row

For i = LR To 2 Step -1
If Cells(i, "A") = Cells(i - 1, "A") And _
Cells(i, "E") = Cells(i - 1, "E") Then _
Rows(i).Delete xlShiftUp
End If
Next i

Application.ScreenUpdating = True
End Sub
========

Does that help?

--
"Actually, I *am* a rocket scientist." -- JB
(www.MadRocketScientist.com)

Your feedback is appreciated, click YES if this post helped you.


"Monk" wrote:

> I have a range of data in cells A1:K1000 and some of the row data in that
> range has been partially duplicated. What I would like to do is to delete
> the duplicated row if the cell values in column A are the same as well as the
> data in Column E.
>
> For example:
> If cell A1 (Smith) and A2 (Smith) are the same and cells E1 (Microsoft) and
> E2 (Microsoft) are the same, delete row 2. However If cell A1 (Smith) and A2
> (Smith) are the same and cells E1 (Microsoft) and E2 (Apple) are different,
> then this is not a duplicate so it should not be deleted.
>
> Any assistance would be appreciated.

 
Reply With Quote
 
om
Guest
Posts: n/a
 
      17th Nov 2009
Hi

Easier approach to do this - -

Data>Filter>Advanced Filter --select Unique records only

This will filter the unique records.. then u can select copy to another
location

Regards
Om

"JBeaucaire" wrote:

> Try this:
>
> ========
> Sub DeleteDupes()
> 'JBeaucaire (11/16/2009)
> Dim LR As Long, i As Long
> Application.ScreenUpdating = False
>
> LR = Range("A" & Rows.Count).End(xlUp).Row
>
> For i = LR To 2 Step -1
> If Cells(i, "A") = Cells(i - 1, "A") And _
> Cells(i, "E") = Cells(i - 1, "E") Then _
> Rows(i).Delete xlShiftUp
> End If
> Next i
>
> Application.ScreenUpdating = True
> End Sub
> ========
>
> Does that help?
>
> --
> "Actually, I *am* a rocket scientist." -- JB
> (www.MadRocketScientist.com)
>
> Your feedback is appreciated, click YES if this post helped you.
>
>
> "Monk" wrote:
>
> > I have a range of data in cells A1:K1000 and some of the row data in that
> > range has been partially duplicated. What I would like to do is to delete
> > the duplicated row if the cell values in column A are the same as well as the
> > data in Column E.
> >
> > For example:
> > If cell A1 (Smith) and A2 (Smith) are the same and cells E1 (Microsoft) and
> > E2 (Microsoft) are the same, delete row 2. However If cell A1 (Smith) and A2
> > (Smith) are the same and cells E1 (Microsoft) and E2 (Apple) are different,
> > then this is not a duplicate so it should not be deleted.
> >
> > Any assistance would be appreciated.

 
Reply With Quote
 
JBeaucaire
Guest
Posts: n/a
 
      17th Nov 2009
How would you use Adv Filter to select unique based on columns A and E only
at the same time?

--
"Actually, I *am* a rocket scientist." -- JB
(www.MadRocketScientist.com)

Your feedback is appreciated, click YES if this post helped you.


"om" wrote:

> Hi
>
> Easier approach to do this - -
>
> Data>Filter>Advanced Filter --select Unique records only
>
> This will filter the unique records.. then u can select copy to another
> location
>
> Regards
> Om

 
Reply With Quote
 
Monk
Guest
Posts: n/a
 
      17th Nov 2009
I got a compile error on the End if line so I removed that and it works
perfectly. Exactly what I was looking for. Much appreciated.

"JBeaucaire" wrote:

> Try this:
>
> ========
> Sub DeleteDupes()
> 'JBeaucaire (11/16/2009)
> Dim LR As Long, i As Long
> Application.ScreenUpdating = False
>
> LR = Range("A" & Rows.Count).End(xlUp).Row
>
> For i = LR To 2 Step -1
> If Cells(i, "A") = Cells(i - 1, "A") And _
> Cells(i, "E") = Cells(i - 1, "E") Then _
> Rows(i).Delete xlShiftUp
> End If
> Next i
>
> Application.ScreenUpdating = True
> End Sub
> ========
>
> Does that help?
>
> --
> "Actually, I *am* a rocket scientist." -- JB
> (www.MadRocketScientist.com)
>
> Your feedback is appreciated, click YES if this post helped you.
>
>
> "Monk" wrote:
>
> > I have a range of data in cells A1:K1000 and some of the row data in that
> > range has been partially duplicated. What I would like to do is to delete
> > the duplicated row if the cell values in column A are the same as well as the
> > data in Column E.
> >
> > For example:
> > If cell A1 (Smith) and A2 (Smith) are the same and cells E1 (Microsoft) and
> > E2 (Microsoft) are the same, delete row 2. However If cell A1 (Smith) and A2
> > (Smith) are the same and cells E1 (Microsoft) and E2 (Apple) are different,
> > then this is not a duplicate so it should not be deleted.
> >
> > Any assistance would be appreciated.

 
Reply With Quote
 
JBeaucaire
Guest
Posts: n/a
 
      17th Nov 2009
Sorry, I noticed that error after I'd posted, and you can't edit these
newsgroup posting. Glad you spotted it.

Your feedback is appreciated, click YES if this post helped you.

-Jerry

"Monk" wrote:

> I got a compile error on the End if line so I removed that and it works
> perfectly. Exactly what I was looking for. Much appreciated.
>
> "JBeaucaire" wrote:
>
> > Try this:
> >
> > ========
> > Sub DeleteDupes()
> > 'JBeaucaire (11/16/2009)
> > Dim LR As Long, i As Long
> > Application.ScreenUpdating = False
> >
> > LR = Range("A" & Rows.Count).End(xlUp).Row
> >
> > For i = LR To 2 Step -1
> > If Cells(i, "A") = Cells(i - 1, "A") And _
> > Cells(i, "E") = Cells(i - 1, "E") Then _
> > Rows(i).Delete xlShiftUp
> > End If
> > Next i
> >
> > Application.ScreenUpdating = True
> > End Sub
> > ========
> >
> > Does that help?
> >
> > --
> > "Actually, I *am* a rocket scientist." -- JB
> > (www.MadRocketScientist.com)
> >
> > Your feedback is appreciated, click YES if this post helped you.
> >
> >
> > "Monk" wrote:
> >
> > > I have a range of data in cells A1:K1000 and some of the row data in that
> > > range has been partially duplicated. What I would like to do is to delete
> > > the duplicated row if the cell values in column A are the same as well as the
> > > data in Column E.
> > >
> > > For example:
> > > If cell A1 (Smith) and A2 (Smith) are the same and cells E1 (Microsoft) and
> > > E2 (Microsoft) are the same, delete row 2. However If cell A1 (Smith) and A2
> > > (Smith) are the same and cells E1 (Microsoft) and E2 (Apple) are different,
> > > then this is not a duplicate so it should not be deleted.
> > >
> > > Any assistance would be appreciated.

 
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
Transpose Rows to Columns based on Like Data web1@umarwadia.com Microsoft Excel Programming 2 11th Oct 2007 06:23 PM
Deleting rows based on data NOT meeting criteria --working macro here, just need help with tweaking Zarlot531 Microsoft Excel Programming 4 29th Apr 2007 12:40 AM
Deleting Rows with data duplicated in 2 columns meganryan@yesonline.com.au Microsoft Excel Worksheet Functions 7 10th Apr 2007 07:18 PM
Comparing columns and deleting rows based on criteria =?Utf-8?B?QUxBVEw=?= Microsoft Excel Programming 3 6th Nov 2006 04:34 PM
Auto Deleting Rows Based on Cell Data kukarooza Microsoft Excel Misc 3 3rd Sep 2004 09:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:11 PM.