如何计算excel中的字母数字元素?

时间:2017-03-21 04:58:02

标签: excel excel-formula countif

我的系列就像下面的excel一样。

804
335123
335123
1210FC245
1210FC245
182663
1220FC140
700107
139562
MANUAL

结果应为“3”,因为它包含字母数字值,但不仅包含数字或仅包含字符。

3 个答案:

答案 0 :(得分:0)

我使用了3个中间步骤来得出答案。如果这是解决这个问题的最佳方法,我不知道,但这肯定是一种方式。

公式视图:

Formulas View

输出:

Values View

<强>更新

在这里,我通过结合两个先前使用的中间步骤来缩短过程。

公式视图(V2):

Formula View

输出保持不变,正如预期的那样。

答案 1 :(得分:0)

也许是用户定义的函数(又名UDF)。

Function countAphaNumeric(rng As Range) As Long
    Dim a As Long, n As Long, str As String, r As Range

    Set rng = Intersect(rng, rng.Parent.UsedRange)

    For Each r In rng
        str = r.Value2
        For a = 65 To 90
            If CBool(InStr(1, str, Chr(a), vbTextCompare)) Then Exit For
        Next a
        For n = 48 To 57
            If CBool(InStr(1, str, Chr(n), vbTextCompare)) Then Exit For
        Next n
        countAphaNumeric = countAphaNumeric - CBool(CBool(a <= 90) And CBool(n <= 57))
    Next r

End Function

enter image description here

答案 2 :(得分:0)

在B2中使用辅助列写:

=--(SUMPRODUCT(COUNTIF(A2,"*"&ROW($A$1:$A$10)-1&"*"))>0)

然后只是简化你的结果

=SUM(B2:B1000)