[英]vba excel macro not case sensitive
I have this code and I need some help in makeing it not case sensitive. 我有这段代码,我需要一些帮助使其不区分大小写。 Right now the serch is case sensitive and I have some excel tables that contains data that are both in uppercase and inlowercase.
现在,serch区分大小写,我有一些excel表,其中包含大写和小写的数据。 Thanks
谢谢
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
Change this one line 更改这一行
StartPos = InStr(Ucase(cl), Ucase(SearchText)) StartPos = InStr(Ucase(cl),Ucase(SearchText))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.