公式来找到句子中的大写字母为真

公式来找到句子中的大写字母为真

我有一张工作表,其中大写单词之间有一个句子,我想知道哪些单元格中的句子有一个大写单词。请有人帮我找到正确的公式。

我尝试使用下面的公式,但只有当右侧出现大写字母时,该公式才会给出结果。

=IF(CODE(RIGHT(C3,1))>96,"下","上")

在此处输入图片描述

答案1

你的问题不清楚,但这应该能让你明白

Sub AvoidThePirates()

Dim startRow As Integer
startRow = 2    ' EDIT THIS ME HEARTIES

Dim columnToLookUp As String
columnToLookUp = "C" ' Arrrgh ye scurvy sea dog

Dim columnResults As String
columnResults = "D" ' Show me ya gold

'Touch below this and I'll feed ya to the sharks

Dim isUpper As Boolean


Do While (Range(columnToLookUp & startRow).Value <> "")

    Dim hasUpper As Boolean
    hasUpper = False

    isUpper = False

    Dim valueToCheck As String
    valueToCheck = Range(columnToLookUp & startRow).Value
    valueToCheck = Replace(valueToCheck, ".", "")

    Dim i As Integer

    For i = 0 To Len(valueToCheck)
        Dim chara As String
        chara = Mid(valueToCheck, i + 1, 1)
        If IsLetter(chara) Then
           If StrComp(chara, UCase(chara), vbBinaryCompare) = 0 Then
                Dim charaB As String
                charaB = Mid(valueToCheck, i + 2, 1)
                If IsLetter(charaB) Then

                   If StrComp(charaB, UCase(charaB), vbBinaryCompare) = 0 Then
                       isUpper = True
                        Exit For
                   End If

                End If
           End If
        End If
    Next i

    If (isUpper) Then
    Range(columnResults & startRow).Value = "UPPER"
    Else
    Range(columnResults & startRow).Value = "lower"
    End If


    startRow = startRow + 1
Loop


End Sub


Function IsLetter(strValue As String) As Boolean
    Dim intPos As Integer
    For intPos = 1 To Len(strValue)
        Select Case Asc(Mid(strValue, intPos, 1))
            Case 65 To 90, 97 To 122
                IsLetter = True
            Case Else
                IsLetter = False
                Exit For
        End Select
    Next
End Function

在此处输入图片描述

VBa 运行后

在此处输入图片描述

另请参阅如何在 MS Office 中添加 VBA?

相关内容