簡體   English   中英

VBA Excel宏不區分大小寫

[英]vba excel macro not case sensitive

我有這段代碼,我需要一些幫助使其不區分大小寫。 現在,serch區分大小寫,我有一些excel表,其中包含大寫和小寫的數據。 謝謝

Sub FormatSelection()

    Dim cl As Range
    Dim SearchText As String
    Dim StartPos As Integer
    Dim EndPos As Integer
    Dim TestPos As Integer
    Dim TotalLen As Integer

    On Error Resume Next
    Application.DisplayAlerts = False
    SearchText = Application.InputBox _
    (Prompt:="Enter string.", Title:="Which string to format?", Type:=2)
    On Error GoTo 0
    Application.DisplayAlerts = True
    If SearchText = "" Then
        Exit Sub
    Else
        For Each cl In Selection
          TotalLen = Len(SearchText)
          StartPos = InStr(cl, SearchText)
          TestPos = 0
          Do While StartPos > TestPos
            With cl.Characters(StartPos, TotalLen).Font
              .FontStyle = "Bold"
              .ColorIndex = 3
            End With
            EndPos = StartPos + TotalLen
            TestPos = TestPos + EndPos
            StartPos = InStr(TestPos, cl, SearchText, vbTextCompare)
          Loop
        Next cl
    End If
End Sub

更改這一行

StartPos = InStr(Ucase(cl),Ucase(SearchText))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM