|
上面截图里,C:D列是A列数据用自定义函数ZFCJS普通和区域数组公式得出的计算结果,现在需要:
全部保留自定义函数ZFCJS的计算功能和显示格式,只是让显示的结果比实际计算结果小“1”,如C5:D5,原来显示“9”,现在就像E列那样显示“8”。
代码如下:
Function ZFCJS(rgSource As Range) As Variant
Dim arrSource As Variant, arrResult As Variant
Dim lngRow As Long
Dim strTemp As String, strChar As String
Dim intLen As Integer
Dim objDic As Object
If rgSource.Count = 1 Then
ReDim arrSource(1 To 1, 1 To 1)
arrSource(1, 1) = rgSource
Else
arrSource = rgSource
End If
arrResult = arrSource
Set objDic = CreateObject("Scripting.Dictionary")
For lngRow = LBound(arrSource) To UBound(arrSource)
strTemp = arrSource(lngRow, 1)
strTemp = Trim(strTemp)
objDic.RemoveAll
For intLen = 1 To Len(strTemp)
strChar = Mid(strTemp, intLen, 1)
If Trim(strChar) <> "" Then objDic(strChar) = ""
Next
arrResult(lngRow, 1) = IIf(objDic.Count = 0, "", objDic.Count)
Next
Set objDic = Nothing
ZFCJS = arrResult
End Function
我想应该是在上面的代码里,用各行不重复数据的总个数减去“1”就行了!唉,只能恨自己技术太菜,把上面的代码都揉搓烂了也没有得到想要的结果,只得恳请大神们帮忙了!
怎样让计算结果比原来少“1”.zip
(430.56 KB, 下载次数: 5)
|
|