PC Review


Reply
Thread Tools Rate Thread

delete duplicate records

 
 
Krystal Peters
Guest
Posts: n/a
 
      9th Oct 2009
Have client request worksheet that has duplicates that must be removed so
clients are not overcharged. The second column (below) indicates the number
of
request received & max # of rows to delete. I have run into a problem when
the max # of rows to delete is more than the records available.

Sample:

ACCT_NO Requests Found
289278995 1
289278999 1
870587008 1
119387014 1
158675527 2
654375649 2
569777245 2
752478468 2
752478468 2
396378512 2
396378512 2
396378512 2
396378512 2
399778090 3
399778090 3
399778090 3
208777882 4
208777882 4
208777882 4
208777882 4
987178737 4
987178737 4
117468837 7
117468837 7
117468837 7
117468837 7

Code used:
sr = currentrow
For counter = 1 To countrows
delrow = ActiveSheet.Cells(sr, 7).Value 'On Paste_Accounts
acct1 = ActiveSheet.Cells(sr, 5).Value 'Acct # 1
acct2 = ActiveSheet.Cells(sr + 1, 5).Value 'Acct #2

If acct1 <> acct2 Then
If delrow = 1 Then
ActiveSheet.Cells(sr, 1).Select
Selection.EntireRow.Delete
End If

If delrow > 1 Then
r1 = (sr + 1) - delrow
r2 = sr
accts = ActiveSheet.Cells(r1, 5).Value
If accts = acct1 Then
Rows(r1 & ":" & r2).Select
Selection.EntireRow.Delete
sr = r1
Else
Rows(r2).Select
Selection.EntireRow.Delete
End If

End If
Else
sr = sr + 1
End If
Next counter
End Sub

Any help / suggestions would be appreciated.
 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      9th Oct 2009
Is that only COL A you want to ..Then try the below macro

-With data in Column A (cell A1 should have a header)..run this macro which
will insert a sheet after the current sheet and generate a list of unique
account numbers. Try and feedback

Sub Macro()
Dim ws1 As Worksheet, ws2 As Worksheet
Set ws1 = ActiveSheet
Set ws2 = Worksheets.Add(After:=ActiveSheet)
ws1.Columns("A:A").AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=ws2.Range("A1"), Unique:=True
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Krystal Peters" wrote:

> Have client request worksheet that has duplicates that must be removed so
> clients are not overcharged. The second column (below) indicates the number
> of
> request received & max # of rows to delete. I have run into a problem when
> the max # of rows to delete is more than the records available.
>
> Sample:
>
> ACCT_NO Requests Found
> 289278995 1
> 289278999 1
> 870587008 1
> 119387014 1
> 158675527 2
> 654375649 2
> 569777245 2
> 752478468 2
> 752478468 2
> 396378512 2
> 396378512 2
> 396378512 2
> 396378512 2
> 399778090 3
> 399778090 3
> 399778090 3
> 208777882 4
> 208777882 4
> 208777882 4
> 208777882 4
> 987178737 4
> 987178737 4
> 117468837 7
> 117468837 7
> 117468837 7
> 117468837 7
>
> Code used:
> sr = currentrow
> For counter = 1 To countrows
> delrow = ActiveSheet.Cells(sr, 7).Value 'On Paste_Accounts
> acct1 = ActiveSheet.Cells(sr, 5).Value 'Acct # 1
> acct2 = ActiveSheet.Cells(sr + 1, 5).Value 'Acct #2
>
> If acct1 <> acct2 Then
> If delrow = 1 Then
> ActiveSheet.Cells(sr, 1).Select
> Selection.EntireRow.Delete
> End If
>
> If delrow > 1 Then
> r1 = (sr + 1) - delrow
> r2 = sr
> accts = ActiveSheet.Cells(r1, 5).Value
> If accts = acct1 Then
> Rows(r1 & ":" & r2).Select
> Selection.EntireRow.Delete
> sr = r1
> Else
> Rows(r2).Select
> Selection.EntireRow.Delete
> End If
>
> End If
> Else
> sr = sr + 1
> End If
> Next counter
> End Sub
>
> Any help / suggestions would be appreciated.

 
Reply With Quote
 
Krystal Peters
Guest
Posts: n/a
 
      9th Oct 2009
My apologies, I was not clear.

If for an acct there is only 1 request found and only 1 record then it's to
be deleted but if only 1 request is found but there is 2 or more rows with
the acct # then only delete 1 rows. But if 4 requests are found for an
account and there is only 1 record then that record should be deleted. The
max number to be delete is based on the requests found. Does that help?


"Jacob Skaria" wrote:

> Is that only COL A you want to ..Then try the below macro
>
> -With data in Column A (cell A1 should have a header)..run this macro which
> will insert a sheet after the current sheet and generate a list of unique
> account numbers. Try and feedback
>
> Sub Macro()
> Dim ws1 As Worksheet, ws2 As Worksheet
> Set ws1 = ActiveSheet
> Set ws2 = Worksheets.Add(After:=ActiveSheet)
> ws1.Columns("A:A").AdvancedFilter Action:=xlFilterCopy, _
> CopyToRange:=ws2.Range("A1"), Unique:=True
> End Sub
>
> If this post helps click Yes
> ---------------
> Jacob Skaria
>
>
> "Krystal Peters" wrote:
>
> > Have client request worksheet that has duplicates that must be removed so
> > clients are not overcharged. The second column (below) indicates the number
> > of
> > request received & max # of rows to delete. I have run into a problem when
> > the max # of rows to delete is more than the records available.
> >
> > Sample:
> >
> > ACCT_NO Requests Found
> > 289278995 1
> > 289278999 1
> > 870587008 1
> > 119387014 1
> > 158675527 2
> > 654375649 2
> > 569777245 2
> > 752478468 2
> > 752478468 2
> > 396378512 2
> > 396378512 2
> > 396378512 2
> > 396378512 2
> > 399778090 3
> > 399778090 3
> > 399778090 3
> > 208777882 4
> > 208777882 4
> > 208777882 4
> > 208777882 4
> > 987178737 4
> > 987178737 4
> > 117468837 7
> > 117468837 7
> > 117468837 7
> > 117468837 7
> >
> > Code used:
> > sr = currentrow
> > For counter = 1 To countrows
> > delrow = ActiveSheet.Cells(sr, 7).Value 'On Paste_Accounts
> > acct1 = ActiveSheet.Cells(sr, 5).Value 'Acct # 1
> > acct2 = ActiveSheet.Cells(sr + 1, 5).Value 'Acct #2
> >
> > If acct1 <> acct2 Then
> > If delrow = 1 Then
> > ActiveSheet.Cells(sr, 1).Select
> > Selection.EntireRow.Delete
> > End If
> >
> > If delrow > 1 Then
> > r1 = (sr + 1) - delrow
> > r2 = sr
> > accts = ActiveSheet.Cells(r1, 5).Value
> > If accts = acct1 Then
> > Rows(r1 & ":" & r2).Select
> > Selection.EntireRow.Delete
> > sr = r1
> > Else
> > Rows(r2).Select
> > Selection.EntireRow.Delete
> > End If
> >
> > End If
> > Else
> > sr = sr + 1
> > End If
> > Next counter
> > End Sub
> >
> > Any help / suggestions 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
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
Delete records when certain records have duplicate column data JVroom Microsoft Excel New Users 0 26th Jan 2009 05:07 PM
how to delete duplicate records in a row =?Utf-8?B?Q2hyaXN0aWFu?= Microsoft Excel Setup 2 21st Jul 2006 01:39 AM
Delete Duplicate Records =?Utf-8?B?QWxpY2U=?= Microsoft Access Queries 1 10th Nov 2005 02:28 PM
Delete duplicate records Ellen Microsoft Access Queries 2 9th Apr 2004 06:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:25 PM.