我想计算一个单元格中出现了多少个小写字符,然后出现了多少个大写字符以及出现了多少个特殊字符。我怎样才能实现这样的目标?
问问题
752 次
2 回答
2
考虑以下四个用户定义函数:
Public Function LowC(r As Range) As Long
Dim s As String, ch As String
Dim IAmTheCount As Long, L As Long
s = r.Text
IAmTheCount = 0
For L = 1 To Len(s)
If Mid(s, L, 1) Like "[a-z]" Then
IAmTheCount = IAmTheCount + 1
End If
Next L
LowC = IAmTheCount
End Function
Public Function HighC(r As Range) As Long
Dim s As String, ch As String
Dim IAmTheCount As Long, L As Long
s = r.Text
IAmTheCount = 0
For L = 1 To Len(s)
If Mid(s, L, 1) Like "[A-Z]" Then
IAmTheCount = IAmTheCount + 1
End If
Next L
HighC = IAmTheCount
End Function
Public Function NumC(r As Range) As Long
Dim s As String, ch As String
Dim IAmTheCount As Long, L As Long
s = r.Text
IAmTheCount = 0
For L = 1 To Len(s)
If Mid(s, L, 1) Like "[0-9]" Then
IAmTheCount = IAmTheCount + 1
End If
Next L
NumC = IAmTheCount
End Function
Public Function OtherC(r As Range) As Long
OtherC = Len(r.Text) - LowC(r) - HighC(r) - NumC(r)
End Function
它们将返回单个单元格中大写、小写、数字和其他字符的数量。
于 2013-11-10T14:45:46.053 回答
0
尽管 VBA 对我来说似乎要简单得多,但 Excel 函数是可能的。
使用 Excel 函数:
大写计数:
=SUMPRODUCT((MID(A1,ROW(INDIRECT("1:99")),1)>="A")*(MID(A1,ROW(INDIRECT("1:99")),1)<="Z")*EXACT(MID(A1,ROW(INDIRECT("1:99")),1),UPPER(MID(A1,ROW(INDIRECT("1:99")),1))))
小写计数
SUMPRODUCT((MID(A1,ROW(INDIRECT("1:99")),1)>="A")*(MID(A1,ROW(INDIRECT("1:99")),1)<="Z")*EXACT(MID(A1,ROW(INDIRECT("1:99")),1),LOWER(MID(A1,ROW(INDIRECT("1:99")),1))))
数字计数
=SUMPRODUCT(--ISNUMBER(-MID(A1,ROW(INDIRECT("1:99")),1)))
特价商品
=LEN(A1)-SUM(SUMPRODUCT((MID(A1,ROW(INDIRECT("1:99")),1)>="A")*(MID(A1,ROW(INDIRECT("1:99")),1)<="Z")*EXACT(MID(A1,ROW(INDIRECT("1:99")),1),UPPER(MID(A1,ROW(INDIRECT("1:99")),1)))),SUMPRODUCT((MID(A1,ROW(INDIRECT("1:99")),1)>="A")*(MID(A1,ROW(INDIRECT("1:99")),1)<="Z")*EXACT(MID(A1,ROW(INDIRECT("1:99")),1),LOWER(MID(A1,ROW(INDIRECT("1:99")),1)))),SUMPRODUCT(--ISNUMBER(-MID(A1,ROW(INDIRECT("1:99")),1))))
于 2013-11-10T20:54:11.650 回答