Welcome to Lockergnome.com!
HomeHome FAQFAQ   SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log in/Register/PasswordLog in/Register/Password

delete duplicate rows in excel

 
   Home -> Office -> General Discussions RSS
Next:  General Discussions: update and export Excel charts as images  
Author Message
lefty55




Joined: Apr 24, 2008
Posts: 2



(Msg. 1) Posted: Thu Apr 24, 2008 1:07 pm
Post subject: delete duplicate rows in excel

I have a spreadsheet with columns a through f. Column "C" is an invoice # and is listed multiple times, depending on the number of items billed on this invoice. I'm trying to delete all multiple copies of this invoice leaving only the first instance of each (the first entry has the total sale). I found a macro on this forum from a while back and it will delete my duplicate invoices if I insert my invoice # to Column "A", but it get's my other columns out of sync. I think this macro was written for a two column spreadsheet. Here is the Macro that almost works:
Sub DeleteDupes()
Dim Iloop As Integer
Dim Numrows As Integer

'Turn off warnings, etc.
Application.ScreenUpdating = False
Application.DisplayAlerts = False

Numrows = Range("A65536").End(xlUp).Row
Range("A1:B" & Numrows).Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, _
Key2:=Range("B1"), Order2:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
For Iloop = Numrows To 2 Step -1
If Cells(Iloop, "A") + Cells(Iloop, "B") = Cells(Iloop - 1, "A") + _
Cells(Iloop - 1, "B") Then
Rows(Iloop).Delete
End If
Next Iloop

'Turn on warnings, etc.
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub


I'm not familiar enough with Macroes to know how to adapt this. Any help would be greatly appreciated.
Marv
Back to top
Login to vote
SOS




Joined: May 28, 2008
Posts: 3



(Msg. 2) Posted: Wed May 28, 2008 9:56 am
Post subject:

Hi lefty55,

If you have your invoice numbers in Col A the following code loops through from the bottom of the range upwards and if it finds the same invoice number it deletes the duplicate row(s) leaving only the first instance of the invoice number.

Code:
Dim Iloop As Integer
Dim Numrows As Integer

'Turn off warnings, etc.
Application.ScreenUpdating = False
Application.DisplayAlerts = False

Numrows = Range("A65536").End(xlUp).Row
Range("A1:F" & Numrows).Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, _
Key2:=Range("B1"), Order2:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
For Iloop = Numrows To 2 Step -1
  If Cells(Iloop, 1).Value = Cells(Iloop - 1, 1).Value Then
     Rows(Iloop).Delete
End If
Next Iloop

'Turn on warnings, etc.
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub


Hope this helps

Seamus
Back to top
Login to vote
lefty55




Joined: Apr 24, 2008
Posts: 2



(Msg. 3) Posted: Thu May 29, 2008 5:40 pm
Post subject:

Thanks very much for the reply. I've got my spreadsheet working now but I printed your solution for future reference if needed. Sorry for not posting that a solution had been found.
Back to top
Login to vote
Display posts from previous:   
       Home -> Office -> General Discussions All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Categories:
 General
 Microsoft Windows XP
 Microsoft Windows Vista
 Microsoft Windows (other)
  Microsoft Office
 Microsoft Office (other)
 Computer Security
 Linux
 Movies


[ Contact us | Terms of Service/Privacy Policy ]