Question : How to count repeated row in an Excel worksheet

I have an excel with 29,000 rows.  I need to know how many are duplicate and of eac how many.  For example: if the data rows are the following:

000000000000020
000000000000030
000000000000042
000000000000042
000000000000042
000000000000045
000000000000051

I would like to know the following:

000000000000020 is 1
000000000000030 is 1
000000000000042 is 3
000000000000045 is 1
000000000000051 is 1

I have used a combination of sort then subtotal (count); and it gives what I want but it takes a real long time.

Is there another function to get the same results?

I have excel 2007

Answer : How to count repeated row in an Excel worksheet

I'm assuming from your question that you want to be able to repeat this operation. The UDF below will produce the desired results and the source data does not need to be sorted.

The UDF (User Defined Function) below takes a range of values and creates a list of unique keys along with a count of occurrences of each value. The UDF syntax is:

   =Counts(Values)

The function returns an array and so needs to be entered as a multiple cell array formula. To enter the formula, select an area two columns wide and as many rows tall as will be needed to display the results. Enter the formula in the formula bar and press CTRL+SHIFT+ENTER.

Public Function Counts( _
      ByVal Values As Variant _
   ) As Variant

' Produce a tally of all unique keys from the specified key range and, for each, include a
' count of how many times it occurs.

' This is a multiple cell array formula.

' © 2009 Kevin Jones

   Dim Result As Variant
   Dim Keys As New Collection
   Dim Row As Long
   Dim Cell As Range
   
   Application.Volatile

   ReDim Result(1 To Application.Caller.Rows.Count, 1 To 2)

   ' Inialize values to empty so errors don't appear in spreadsheet
   For Row = 1 To Application.Caller.Rows.Count
      Result(Row, 1) = ""
      Result(Row, 2) = ""
   Next Row
   
   ' Create collection of all unique keys
   On Error Resume Next
   For Each Cell In Values
      If Len(Cell) > 0 Then
         Keys.Add Cell, CStr(Cell)
      End If
   Next Cell
   On Error GoTo 0

   ' Set return values
   For Row = 1 To Application.Min(UBound(Result, 1), Keys.Count)
      Result(Row, 1) = Keys(Row)
      Result(Row, 2) = Application.CountIf(Values, Keys(Row))
   Next Row
   
   ' Add note if destination range not large enough
   If Keys.Count > UBound(Result, 1) Then
      Result(UBound(Result), 1) = "More..."
      Result(UBound(Result), 2) = ""
   End If

   ' Return result
   Counts = Result

End Function

Kevin
Random Solutions  
 
programming4us programming4us