Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I started out with this data</p> <p><img src="https://i.stack.imgur.com/iIH6J.jpg" alt="Original"></p> <p>and used the following code to read it into an array, sort the array, and count the duplicate values, then output the result to sheet2</p> <pre><code>Sub Example() Dim vCell As Range Dim vRng() As Variant Dim i As Integer ReDim vRng(0 To 0) As Variant Sheets("Sheet2").Cells.Delete Sheets("Sheet1").Select For Each vCell In ActiveSheet.UsedRange If vCell.Value &lt;&gt; "" Then ReDim Preserve vRng(0 To i) As Variant vRng(i) = vCell.Value i = i + 1 End If Next vRng = CountDuplicates(vRng) Sheets("Sheet2").Select Range(Cells(1, 1), Cells(UBound(vRng), UBound(vRng, 2))) = vRng Rows(1).Insert Range("A1:B1") = Array("Entry", "Times Entered") ActiveSheet.UsedRange.Sort Range("B1"), xlDescending End Sub Function CountDuplicates(List() As Variant) As Variant() Dim CurVal As String Dim NxtVal As String Dim DupCnt As Integer Dim Result() As Variant Dim i As Integer Dim x As Integer ReDim Result(1 To 2, 0 To 0) As Variant List = SortAZ(List) For i = 0 To UBound(List) CurVal = List(i) If i = UBound(List) Then NxtVal = "" Else NxtVal = List(i + 1) End If If CurVal = NxtVal Then DupCnt = DupCnt + 1 Else DupCnt = DupCnt + 1 ReDim Preserve Result(1 To 2, 0 To x) As Variant Result(1, x) = CurVal Result(2, x) = DupCnt x = x + 1 DupCnt = 0 End If Next Result = WorksheetFunction.Transpose(Result) CountDuplicates = Result End Function Function SortAZ(MyArray() As Variant) As Variant() Dim First As Integer Dim Last As Integer Dim i As Integer Dim x As Integer Dim Temp As String First = LBound(MyArray) Last = UBound(MyArray) For i = First To Last - 1 For x = i + 1 To Last If MyArray(i) &gt; MyArray(x) Then Temp = MyArray(x) MyArray(x) = MyArray(i) MyArray(i) = Temp End If Next Next SortAZ = MyArray End Function </code></pre> <p>End Result:</p> <p><img src="https://i.stack.imgur.com/g4BFU.jpg" alt="Result"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload