我正在寻找一个公式来列出值的出现次数,只要它们大于2次;结果将显示在图像中。
例如,如果值重复2次,则显示为“2”,3次显示为“3”。因此,如果在该范围内有两个数字重复,那么它将显示为“32”,如下图所示。 (数字之间不需要逗号)。感谢。
答案 0 :(得分:2)
这是一个简单的UDF:
{
"arr_vs":{
"one":[
{
"val":5,
"total_count":2
},{
"val":2,
"total_count":
}
}],
"two":[
{
"val":5,
"total_count":2
},{
"val":2,
"total_count":
}
}]
}
}
所以你在表格上的电话会是:
Function mycount(rng As Range) As String
Dim str As String
Dim rngcnt As Range
For Each rngcnt In rng
If InStr("," & str & ",", "," & rngcnt.Value & ",") = 0 Then
If Application.WorksheetFunction.CountIf(rng, rngcnt) > 1 Then
mycount = mycount & Application.WorksheetFunction.CountIf(rng, rngcnt)
str = str & "," & rngcnt
End If
End If
Next rngcnt
End Function
然后复制。
答案 1 :(得分:2)
我得到它的方法是定义一个VBA函数。这个函数使用一个字典,所以有必要添加对“Microsoft Scripting Runtime”的引用。 (看here)。另外,我使用了一个函数来对来自here
的字符串中的字符进行排序 foreach($a2m as $m ){
echo "<pre>";
print_r($m['CIDADE']);
// print_r($m['CONTA']);
echo "</pre>";
}
?>
毕竟,您将能够在Excel中将该函数用作公式,例如调用它:
Function Repetitions(rng As Range)
Dim dict As New Scripting.Dictionary
Dim res() As Integer
For aux = 1 To rng.Count
Dim numero As Integer
numero = rng.Cells(1, aux).Value
If Not dict.Exists(numero) Then
dict.Add numero, 1
Else
dict(numero) = dict(numero) + 1
End If
Next aux
Dim result As String
result = ""
For aux = 0 To UBound(dict.Items)
If dict.Items(aux) > 1 Then result = result & dict.Items(aux)
Next aux
While Len(result)
iTemp = 1
Temp = Left(result, 1)
For I = 2 To Len(result)
If StrComp(Mid(result, I, 1), Temp, vbTextCompare) = 0 Then
If StrComp(Mid(result, I, 1), Temp, vbBinaryCompare) = 1 Then
Temp = Mid(result, I, 1)
iTemp = I
End If
End If
If StrComp(Mid(result, I, 1), Temp, vbTextCompare) = 1 Then
Temp = Mid(result, I, 1)
iTemp = I
End If
Next I
Repetitions = Repetitions & Temp
result = Left(result, iTemp - 1) & _
Mid(result, iTemp + 1)
Wend
End Function