View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Peter Atherton Peter Atherton is offline
external usenet poster
 
Posts: 31
Default Retain if atleast 4 entries

Randy
The following works
Sub testDel()
Dim myRng As Range
Dim c, s, v
Dim count As Integer, nr As Integer, z As Integer
With Worksheets(1)
Set myRng = .Range("A2", .Cells(.Rows.count, "A").End
(xlUp))
End With
nr = myRng.Rows.count
For s = 2 To nr + 1
Cells(s, 1).Select
v = Cells(s, 1).Value
z = Application.CountIf(myRng, v)
If z < 4 Then
Selection.EntireRow.Delete
count = count + 1
End If
Next s
MsgBox count & " Records have been deleted", , "Deleted _
Record Count"
End Sub

Any problem contact me
Regards
Peter
-----Original Message-----
Hi
I have a unique problem here. I have got an excel file
with almost 2500 rows of data in it. Coulumn "A" contains
the ID # of companies. Each company might have more than
one data entry (row), so it looks something like this:

A B C D E
34982 data data data data
34982 data...
5533812 data...
5533812 data...
5533812 data...
5533812 data...
5533812 data...
456832 data...
456832 data...
456832 data...

What i need to do is to write a program which will look

at
the first column of ID#s and if the ID# occurs less than

4
times, i delete those rows. Basically if a company has
ATLEAST 4 data entries, i have to keep it, if not, delete
entire rows of that company.
Any kind of suggestion would be very helpful! Thanks a

lot
in advance.
.