here is the code that I currently use (I got it here with some help ~2 years ago.)
It captures unique values in column C and then gets a count of those unique values.
It works great.
My question is, if I want to get a count/tally of unique values in other columns (the above code only addresses a single column... column 'C' in this case), can the above procedure be modified to capture not only column C, but also columns D and E?
Here is the original data that is located on the spreadsheet "HELPER" before the script is executed:
Here is what the above code that I posted returns (the code captures each unique value found in column 'C' and then provides a tally for each of those unique values and then posts that value in the adjacent cell):
But here is what I am would like it to do (do not only column C, but also column D and E in the same manner):
Can this be done (more easily or efficiently) with one procedure, or am I better off just having three separate procedures that capture and tally the three separate columns?
(I dont have a problem doing it that way, if I have to... but I am going to have alot of procedures in order to capture and tally all the required data that I am after.)
Thanks for any help or suggestions!
It captures unique values in column C and then gets a count of those unique values.
It works great.
Code:
Dim Cl As Range
Dim Cnt, TmpA, TmpB
Dim i As Long, X As Long
' get a count of all unique values in column C (starting at row 1)
With CreateObject("scripting.dictionary")
For Each Cl In Worksheets("HELPER").Range("C1", Worksheets("HELPER").Range("C" & Rows.Count).End(xlUp))
If Not .Exists(Cl.Value) Then
.Add Cl.Value, 1
Else
.Item(Cl.Value) = .Item(Cl.Value) + 1
End If
Next Cl
ReDim Cnt(0 To .Count - 1, 0 To 1)
For i = 0 To .Count - 1
Cnt(i, 0) = .keys()(i)
Cnt(i, 1) = .Items()(i)
Next i
End With
For i = LBound(Cnt, 1) To UBound(Cnt, 1) - 1
For X = i + 1 To UBound(Cnt, 1)
If Cnt(i, 1) < Cnt(X, 1) Then
TmpA = Cnt(X, 0)
TmpB = Cnt(X, 1)
Cnt(X, 0) = Cnt(i, 0)
Cnt(X, 1) = Cnt(i, 1)
Cnt(i, 0) = TmpA
Cnt(i, 1) = TmpB
End If
Next X
Next i
' take the data that was tallied from above and paste it onto the worksheet: "HELPER1" starting at A1
Worksheets("HELPER1").Range("A" & Rows.Count).End(xlUp).Offset(0).Resize(UBound(Cnt) + 1, 2).Value = Cnt
My question is, if I want to get a count/tally of unique values in other columns (the above code only addresses a single column... column 'C' in this case), can the above procedure be modified to capture not only column C, but also columns D and E?
Here is the original data that is located on the spreadsheet "HELPER" before the script is executed:
Here is what the above code that I posted returns (the code captures each unique value found in column 'C' and then provides a tally for each of those unique values and then posts that value in the adjacent cell):
But here is what I am would like it to do (do not only column C, but also column D and E in the same manner):
Can this be done (more easily or efficiently) with one procedure, or am I better off just having three separate procedures that capture and tally the three separate columns?
(I dont have a problem doing it that way, if I have to... but I am going to have alot of procedures in order to capture and tally all the required data that I am after.)
Thanks for any help or suggestions!