计算单元格中的大写单词和标点符号

我已经使用这个网站很长一段时间来解决我的Excel问题,但一直没能find解决以下问题。 我在单元格B16到B936中有文本string(从大约5个字到1000个字)。 我想实现两件事情:

  1. 为每个单元格计算大于两个字符的大写字母的出现次数。 因此,基本上"I find that StackOverflow is a really GREAT website"将返回得分"1"因为"GREAT"是这个文本string中长度超过2个字符且大写字母的唯一字

  2. 计算在这些文本string中出现多个问号("??", "???", "????", ...) 。 例如: "Are you sure ?? Really sure ???" would return the score "2" "Are you sure ?? Really sure ???" would return the score "2" 。 我尝试过使用一个论坛(LEN - LEN(Substitute(..;"??"))但显然当这个公式遇到一个"????"它返回一个奇怪的结果。

这个给你:

 Function CountUppercaseWords(Expression As String) As Integer Dim SplitArray() As String SplitArray = Split(Expression, " ") Dim I As Integer Dim Count As Integer Dim NextWord As String Count = 0 For I = LBound(SplitArray) To UBound(SplitArray) NextWord = SplitArray(I) If NextWord = UCase(NextWord) And Len(NextWord) >= 2 Then Count = Count + 1 End If Next CountUppercaseWords = Count End Function Function MultipleQuestionMarkOccurences(Expression As String) As Integer Dim I As Integer Dim CurrentLength As Integer Dim Count As Integer Dim NextChar As String Count = 0 CurrentLength = 0 For I = 1 To Len(Expression) NextChar = Mid(Expression, I, 1) If NextChar = "?" Then CurrentLength = CurrentLength + 1 Else CurrentLength = 0 End If If CurrentLength = 2 Then Count = Count + 1 End If Next MultipleQuestionMarkOccurences = Count End Function 

这不是完美的解决scheme,但也许有帮助。 公共函数CountUpperWords(ByVal String1 As String)As Integer

 Dim StringArray() As String ReDim StringArray(Len(String1)) As String Dim String2 As String Dim String2Array() As String ReDim String2Array(UBound(StringArray)) As String Dim isUpper As Boolean String2 = UCase(String1) For i = 0 To Len(String1) ' fragmentation all text to array and make UCase mirror StringArray(i) = Mid(String1, i + 2, 1) 'Function would start from secound character because first character often will be upper String2Array(i) = LCase(StringArray(i)) Next CountUpperCases = 0 For i = 0 To UBound(StringArray) ' compare original text and upper If StringArray(i) <> String2Array(i) Then j = i isUpper = False Do While StringArray(j) <> " " ' checking word is upper If StringArray(j) <> String2Array(j) Then isUpper = True Else isUpper = False End If j = j + 1 Loop If isUpper = True Then CountUpperCases = CountUpperCases + 1 End If i = j End If Next End Function