I would like to keep the most current data in each row (based on column 'f')
where column 'a' equals column 'b'. In the following, row 1, row 6, and row
8 would be kept. The remaining rows would be deleted.
abcdef
1BAC-3901MA09385CPM111341/17/2006
2BAC-3901MA08763CPM949410/28/2005
3BAC-3901MA07924CPM75057/30/2005
4BAC-3901MA07328CPM63456/1/2005
5BAC-3902MA07681CPM69217/1/2005
6BAC-3903MA09109CPM1015812/3/2005
7BAC-3903MA08196CPM81178/26/2005
8BAC-3902MA08837CPM956011/1/2005
9BAC-3902MA06685CPM70777/12/2005
I found the following procedure for what was described as quot;Here's another
procedure that may be useful. Suppose you have two columns of data -- column
A containing some names, and column B containing some dates. If the data is
grouped (not necessarily sorted) by column A (but not necessarily by column
B), this code will delete the duplicates rows, but retaining the latest entry
(by column B) of each name in column Aquot;
Sub DeleteTheOldies()
Dim RowNdx As Long
For RowNdx = Range(quot;A1quot;).End(xlDown).Row To 2 Step -1
If Cells(RowNdx, quot;Aquot;).Value = Cells(RowNdx - 1, quot;Aquot;).Value Then
If Cells(RowNdx, quot;Bquot;).Value lt;= Cells(RowNdx - 1, quot;Bquot;).Value Then
Rows(RowNdx).Delete
Else
Rows(RowNdx - 1).Delete
End If
End If
Next RowNdx
End Sub
I do not really understand this procedure and it also only looking at one
column of data to distinguish duplicates.
Any help is really appreciated!!! Thank you!!
Assuming that you don't have a header row, try this:
Press Ctrl and F11 to open the Visual Basic Editor.
Select Insert and then Module.
Copy the code below and paste it into the module.
Close the Editor.
Go to Tools gt; Macro gt; Macros…
Highlight the macro and click Run.
---------------------------------
Option Explicit
Sub DeleteDupes()
Dim Iloop As Integer
Dim Numrows As Integer
'Turn off warnings, etc.
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Numrows = Range(quot;A65536quot;).End(xlUp).Row
Range(quot;A1:Fquot; amp; Numrows).Select
Selection.Sort Key1:=Range(quot;A1quot;), Order1:=xlAscending, _
Key2:=Range(quot;B1quot;), Order2:=xlAscending, Key3:=Range(quot;F1quot;), _
Order3:=xlDescending, Header:=xlNo, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom
For Iloop = Numrows To 2 Step -1
If Cells(Iloop, quot;Aquot;) amp; Cells(Iloop, quot;Bquot;) = Cells(Iloop - 1, quot;Aquot;) amp; _
Cells(Iloop - 1, quot;Bquot;) Then
Rows(Iloop).Delete
End If
Next Iloop
Range(quot;A1quot;).Select
'Turn on warnings, etc.
Application.DisplayAlerts = True
Application.ScreenUpdating = TrueEnd Sub--
Ken Hudsonquot;Coal Minerquot; wrote:
gt; I would like to keep the most current data in each row (based on column 'f')
gt; where column 'a' equals column 'b'. In the following, row 1, row 6, and row
gt; 8 would be kept. The remaining rows would be deleted.
gt;
gt; abcdef
gt; 1BAC-3901MA09385CPM111341/17/2006
gt; 2BAC-3901MA08763CPM949410/28/2005
gt; 3BAC-3901MA07924CPM75057/30/2005
gt; 4BAC-3901MA07328CPM63456/1/2005
gt; 5BAC-3902MA07681CPM69217/1/2005
gt; 6BAC-3903MA09109CPM1015812/3/2005
gt; 7BAC-3903MA08196CPM81178/26/2005
gt; 8BAC-3902MA08837CPM956011/1/2005
gt; 9BAC-3902MA06685CPM70777/12/2005
gt;
gt; I found the following procedure for what was described as quot;Here's another
gt; procedure that may be useful. Suppose you have two columns of data -- column
gt; A containing some names, and column B containing some dates. If the data is
gt; grouped (not necessarily sorted) by column A (but not necessarily by column
gt; B), this code will delete the duplicates rows, but retaining the latest entry
gt; (by column B) of each name in column Aquot;
gt;
gt; Sub DeleteTheOldies()
gt; Dim RowNdx As Long
gt; For RowNdx = Range(quot;A1quot;).End(xlDown).Row To 2 Step -1
gt; If Cells(RowNdx, quot;Aquot;).Value = Cells(RowNdx - 1, quot;Aquot;).Value Then
gt; If Cells(RowNdx, quot;Bquot;).Value lt;= Cells(RowNdx - 1, quot;Bquot;).Value Then
gt; Rows(RowNdx).Delete
gt; Else
gt; Rows(RowNdx - 1).Delete
gt; End If
gt; End If
gt; Next RowNdx
gt; End Sub
gt;
gt; I do not really understand this procedure and it also only looking at one
gt; column of data to distinguish duplicates.
gt;
gt; Any help is really appreciated!!! Thank you!!
Thanks Ken!!
quot;Ken Hudsonquot; wrote:
gt; Assuming that you don't have a header row, try this:
gt;
gt; Press Ctrl and F11 to open the Visual Basic Editor.
gt; Select Insert and then Module.
gt; Copy the code below and paste it into the module.
gt; Close the Editor.
gt; Go to Tools gt; Macro gt; Macros…
gt; Highlight the macro and click Run.
gt;
gt; ---------------------------------
gt;
gt; Option Explicit
gt; Sub DeleteDupes()
gt; Dim Iloop As Integer
gt; Dim Numrows As Integer
gt;
gt; 'Turn off warnings, etc.
gt; Application.ScreenUpdating = False
gt; Application.DisplayAlerts = False
gt;
gt; Numrows = Range(quot;A65536quot;).End(xlUp).Row
gt; Range(quot;A1:Fquot; amp; Numrows).Select
gt; Selection.Sort Key1:=Range(quot;A1quot;), Order1:=xlAscending, _
gt; Key2:=Range(quot;B1quot;), Order2:=xlAscending, Key3:=Range(quot;F1quot;), _
gt; Order3:=xlDescending, Header:=xlNo, OrderCustom:=1, _
gt; MatchCase:=False, Orientation:=xlTopToBottom
gt; For Iloop = Numrows To 2 Step -1
gt; If Cells(Iloop, quot;Aquot;) amp; Cells(Iloop, quot;Bquot;) = Cells(Iloop - 1, quot;Aquot;) amp; _
gt; Cells(Iloop - 1, quot;Bquot;) Then
gt; Rows(Iloop).Delete
gt; End If
gt; Next Iloop
gt;
gt; Range(quot;A1quot;).Select
gt;
gt; 'Turn on warnings, etc.
gt; Application.DisplayAlerts = True
gt; Application.ScreenUpdating = True
gt;
gt;
gt; End Sub
gt;
gt;
gt; --
gt; Ken Hudson
gt;
gt;
gt; quot;Coal Minerquot; wrote:
gt;
gt; gt; I would like to keep the most current data in each row (based on column 'f')
gt; gt; where column 'a' equals column 'b'. In the following, row 1, row 6, and row
gt; gt; 8 would be kept. The remaining rows would be deleted.
gt; gt;
gt; gt; abcdef
gt; gt; 1BAC-3901MA09385CPM111341/17/2006
gt; gt; 2BAC-3901MA08763CPM949410/28/2005
gt; gt; 3BAC-3901MA07924CPM75057/30/2005
gt; gt; 4BAC-3901MA07328CPM63456/1/2005
gt; gt; 5BAC-3902MA07681CPM69217/1/2005
gt; gt; 6BAC-3903MA09109CPM1015812/3/2005
gt; gt; 7BAC-3903MA08196CPM81178/26/2005
gt; gt; 8BAC-3902MA08837CPM956011/1/2005
gt; gt; 9BAC-3902MA06685CPM70777/12/2005
gt; gt;
gt; gt; I found the following procedure for what was described as quot;Here's another
gt; gt; procedure that may be useful. Suppose you have two columns of data -- column
gt; gt; A containing some names, and column B containing some dates. If the data is
gt; gt; grouped (not necessarily sorted) by column A (but not necessarily by column
gt; gt; B), this code will delete the duplicates rows, but retaining the latest entry
gt; gt; (by column B) of each name in column Aquot;
gt; gt;
gt; gt; Sub DeleteTheOldies()
gt; gt; Dim RowNdx As Long
gt; gt; For RowNdx = Range(quot;A1quot;).End(xlDown).Row To 2 Step -1
gt; gt; If Cells(RowNdx, quot;Aquot;).Value = Cells(RowNdx - 1, quot;Aquot;).Value Then
gt; gt; If Cells(RowNdx, quot;Bquot;).Value lt;= Cells(RowNdx - 1, quot;Bquot;).Value Then
gt; gt; Rows(RowNdx).Delete
gt; gt; Else
gt; gt; Rows(RowNdx - 1).Delete
gt; gt; End If
gt; gt; End If
gt; gt; Next RowNdx
gt; gt; End Sub
gt; gt;
gt; gt; I do not really understand this procedure and it also only looking at one
gt; gt; column of data to distinguish duplicates.
gt; gt;
gt; gt; Any help is really appreciated!!! Thank you!!
- Aug 07 Thu 2008 20:45
Delete rows based on certain criteria
close
全站熱搜
留言列表
發表留言