我已经有时间把它作为一个Excel公式放在一起了。在本文的底部可以看到我的原始评论,以获取我的来源的链接。
步骤来解决此问题:
用户定义函数的细胞
在Excel中创建VBA(一个新的模块排序,让我知道如果你需要在此说明,这只是一对夫妇的点击)
复制并粘贴下面的代码。
Option Explicit
Const c_Separator = "/"
' User Defined Function to split a list within a cell and then sort it
' before recreating a sorted list
Public Function CellSort(strString As String) As String
Dim i As Integer
Dim arr As Variant
Dim strRet As String
arr = Split(strString, c_Separator)
' trim values so sort will work properly
For i = LBound(arr) To UBound(arr)
arr(i) = Trim(arr(i))
Next i
' sort
QuickSort arr, LBound(arr), UBound(arr)
' construct ordered list to return
For i = LBound(arr) To UBound(arr) - 1
strRet = strRet & CStr(arr(i)) & c_Separator
Next i
' Attach the last item separately to avoid adding an unecessary separator
CellSort = strRet & CStr(arr(i))
End Function
' Quick Sort function found here:
' https://stackoverflow.com/questions/3399823/excel-how-do-i-sort-within-a-cell
Public Sub QuickSort(vArray As Variant, inLow As Long, inHi As Long)
Dim pivot As Variant
Dim tmpSwap As Variant
Dim tmpLow As Long
Dim tmpHi As Long
tmpLow = inLow
tmpHi = inHi
pivot = vArray((inLow + inHi) \ 2)
While (tmpLow <= tmpHi)
While (vArray(tmpLow) < pivot And tmpLow < inHi)
tmpLow = tmpLow + 1
Wend
While (pivot < vArray(tmpHi) And tmpHi > inLow)
tmpHi = tmpHi - 1
Wend
If (tmpLow <= tmpHi) Then
tmpSwap = vArray(tmpLow)
vArray(tmpLow) = vArray(tmpHi)
vArray(tmpHi) = tmpSwap
tmpLow = tmpLow + 1
tmpHi = tmpHi - 1
End If
Wend
If (inLow < tmpHi) Then QuickSort vArray, inLow, tmpHi
If (tmpLow < inHi) Then QuickSort vArray, tmpLow, inHi
End Sub
关闭VBA编辑器(不需要更多编码)。
Excel公式计算唯一组合的数量 在Excel中,您可以在原始数据列旁边创建三列。我在下面的屏幕截图中以彩色背景显示了这些公式。每张图片下面都有解释。
蓝柱:采用上面的VBA函数在原始列表中每个单元格的内容进行排序,这给出了一个一致的列表,你可以指望的唯一项目。如果您的原始清单在小写和某些情况下,人在大写,你需要把这些一样,然后修改公式,在此列是=CellSort(UPPER(A2))
绿柱:简单COUNTIF
功能(在最近所有的Excel版本的作品)标识每个排序后的单元格的第一个实例。
红色单元格:计算TRUE出现在绿色列中的次数。这给出了唯一条目的计数。
下面是已完成工作的一个例子。
原始评论
怕我现在没有时间来测试这个权利,但是这可能会帮助你。
你可能想看看这个答案给出的VBA(我没有自己尝试过)。
VBA QuickSort
然后,如果你需要做的这个公式,你可以创建这个VBA用户定义函数来在细胞中的值进行排序。将行arr = Split(ActiveCell.Text, ",")
更改为"/"
,以便它将分割您的列表。
接下来,在原始数据的旁边使用您的公式,然后使用此页上的公式:Count occurrences of values or unique values in a data range来计算唯一。
让我知道如果你需要更多的帮助与上述任何,我会尽力做到明天。
来源
2013-04-04 17:11:00
Jim
这是一个聪明的解... – 2013-04-05 14:34:01