我想實現的是返回列中唯一值(字符串)的列表。將該列表放入數組中,然後將值列表粘貼到新表中,例如A列中。 然後爲每個數組元素計算它發生原始列表的次數,並返回新工作表中列B中的頻率計數反對其獨特的字符串。對於陣列上的每個循環返回每個唯一字符串的計數
這是我的代碼到目前爲止。
Sub UniqueList()
Dim rListPaste As Range
Dim causeList As Range
Dim iReply As Integer
Dim element As Variant
On Error Resume Next
Set rListPaste = Application.InputBox _
(Prompt:="Please select the destination cell", Type:=8)
If rListPaste Is Nothing Then
iReply = MsgBox("No range nominated," _
& " terminate", vbYesNo + vbQuestion)
If iReply = vbYes Then Exit Sub
End If
causeList = Range("E1", Range("E65536").End(xlUp))
Range("causeList").AdvancedFilter Action:=xlFilterCopy, Unique:=True
Range("causeList").AdvancedFilter CopyToRange:=causeList.Cells(1, 1)
element = 0
For Each element In causeList
element = element + 1
Next element
End
End Sub
爲什麼不使用數據透視表? –
WorksheetFunction.Countif函數將返回一個範圍內值的出現次數 - 使用該值而不是最後一次循環。在CopyToRange的結果範圍內使用'For Each Temprangevariable in UniqueRange' - 然後可以將'Temprangevariable.Offset(0,1)'設置爲countif值。 – MattCrum
這可能不是您正在尋找的答案,但它仍然是您執行相同操作的方法:[篩選唯一值](http://office.microsoft.com/zh-cn/excel-help/過濾器爲唯一值或刪除重複值HP010073943.aspx)[計數每個值重複](http://office.microsoft.com/en-us/excel-help/count-occurrences-of -values-or-unique-values-in-a-data-range-HP003056118.aspx) –