[英]Count special characters in range in a function
This function should count all special hidden characters in selected range. 此功能应计算选定范围内的所有特殊隐藏字符。
I got an error. 我有一个错误。 StrIn = C.Text
didn't work. StrIn = C.Text
不起作用。
Function hiddencount(Rng As Range)
Dim C As Range
Dim cnt As Integer
Dim iCh As Integer
Dim StrIn As String
cnt = 0
For Each C In Rng.Cells
C.Value = StrIn
If Not C.HasFormula Then
For iCh = 1 To Len(StrIn)
If Asc(Mid(StrIn, iCh, 1)) < 32 Then
cnt = cnt + 1
End If
Next iCh
Else
End If
Next C
hiddencount = cnt
End Function
In short, change C.Value = StrIn
to StrIn = C.Text
简而言之,将C.Value = StrIn
更改为StrIn = C.Text
You really do not need this variable though. 您实际上确实不需要此变量。 It just creates more code to read through later. 它只是创建更多代码以供日后阅读。 Why not just use C.Text
so it is clear what is being analyzed? 为什么不只使用C.Text
以便清楚地分析什么? Also, if you do not plan on acting on the Else
statement, you can just remove it. 另外,如果您不打算对Else
语句执行操作,则可以将其删除。
Function hiddencount(Rng As Range)
Dim C As Range, cnt As Integer, iCh As Integer
For Each C In Rng.Cells
If Not C.HasFormula Then
For iCh = 1 To Len(C.Text)
If Asc(Mid(C.Text, iCh, 1)) < 32 Then cnt = cnt + 1
Next iCh
End If
Next C
hiddencount = cnt
End Function
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.