使用通配符和解析对象引用的VBA Excel
我试图在输入框中键入搜索字符串,与*通配符一起使用,以搜索选定范围内的字符串实例使用通配符和解析对象引用的VBA Excel,vba,excel,search,wildcard,Vba,Excel,Search,Wildcard,我试图在输入框中键入搜索字符串,与*通配符一起使用,以搜索选定范围内的字符串实例 Sub color() Dim myRange As Range, value As String, wild As Icon value = InputBox("Search String:") If value = vbNullString Then Exit Sub Range("A1").Select Range(Selection, Selection.End(xlToRight)).Select Ra
Sub color()
Dim myRange As Range, value As String, wild As Icon
value = InputBox("Search String:")
If value = vbNullString Then Exit Sub
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
For Each myRange In Selection
If myRange.value = "*" & value & "*" Then
myRange.Interior.ColorIndex = 3
End If
Next myRange
End Sub
另一种可能性:
为什么要使用通配符呢?已经有一个VBA函数用于测试子字符串。尝试:
If InStr(myRange.value,value) > 0 Then
另一种可能性:
为什么要使用通配符呢?已经有一个VBA函数用于测试子字符串。尝试:
If InStr(myRange.value,value) > 0 Then
另一种可能性:
为什么要使用通配符呢?已经有一个VBA函数用于测试子字符串。尝试:
If InStr(myRange.value,value) > 0 Then
另一种可能性:
为什么要使用通配符呢?已经有一个VBA函数用于测试子字符串。尝试:
If InStr(myRange.value,value) > 0 Then
而不是通配符:
Sub color()
Dim myRange As Range, valuee As String
valuee = InputBox("Search String:")
If valuee = vbNullString Then Exit Sub
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
For Each myRange In Selection
If InStr(myRange.value, valuee) > 0 Then
myRange.Interior.ColorIndex = 3
End If
Next myRange
End Sub
我们也可以使用.Find方法
编辑#1:
以下是使用.Find和.FindNext的版本:
Sub color2()
Dim myRange As Range, valuee As String
valuee = InputBox("Search String:")
If valuee = vbNullString Then Exit Sub
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Set myRange = Selection.Find(what:=valuee, after:=Selection(1))
If myRange Is Nothing Then
MsgBox "no value"
Exit Sub
End If
myRange.Interior.ColorIndex = 3
st = myRange.Address(0, 0)
Do Until myRange Is Nothing
Set myRange = Selection.FindNext(after:=myRange)
If myRange.Address(0, 0) = st Then Exit Do
myRange.Interior.ColorIndex = 3
Loop
End Sub
而不是通配符:
Sub color()
Dim myRange As Range, valuee As String
valuee = InputBox("Search String:")
If valuee = vbNullString Then Exit Sub
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
For Each myRange In Selection
If InStr(myRange.value, valuee) > 0 Then
myRange.Interior.ColorIndex = 3
End If
Next myRange
End Sub
我们也可以使用.Find方法
编辑#1:
以下是使用.Find和.FindNext的版本:
Sub color2()
Dim myRange As Range, valuee As String
valuee = InputBox("Search String:")
If valuee = vbNullString Then Exit Sub
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Set myRange = Selection.Find(what:=valuee, after:=Selection(1))
If myRange Is Nothing Then
MsgBox "no value"
Exit Sub
End If
myRange.Interior.ColorIndex = 3
st = myRange.Address(0, 0)
Do Until myRange Is Nothing
Set myRange = Selection.FindNext(after:=myRange)
If myRange.Address(0, 0) = st Then Exit Do
myRange.Interior.ColorIndex = 3
Loop
End Sub
而不是通配符:
Sub color()
Dim myRange As Range, valuee As String
valuee = InputBox("Search String:")
If valuee = vbNullString Then Exit Sub
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
For Each myRange In Selection
If InStr(myRange.value, valuee) > 0 Then
myRange.Interior.ColorIndex = 3
End If
Next myRange
End Sub
我们也可以使用.Find方法
编辑#1:
以下是使用.Find和.FindNext的版本:
Sub color2()
Dim myRange As Range, valuee As String
valuee = InputBox("Search String:")
If valuee = vbNullString Then Exit Sub
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Set myRange = Selection.Find(what:=valuee, after:=Selection(1))
If myRange Is Nothing Then
MsgBox "no value"
Exit Sub
End If
myRange.Interior.ColorIndex = 3
st = myRange.Address(0, 0)
Do Until myRange Is Nothing
Set myRange = Selection.FindNext(after:=myRange)
If myRange.Address(0, 0) = st Then Exit Do
myRange.Interior.ColorIndex = 3
Loop
End Sub
而不是通配符:
Sub color()
Dim myRange As Range, valuee As String
valuee = InputBox("Search String:")
If valuee = vbNullString Then Exit Sub
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
For Each myRange In Selection
If InStr(myRange.value, valuee) > 0 Then
myRange.Interior.ColorIndex = 3
End If
Next myRange
End Sub
我们也可以使用.Find方法
编辑#1:
以下是使用.Find和.FindNext的版本:
Sub color2()
Dim myRange As Range, valuee As String
valuee = InputBox("Search String:")
If valuee = vbNullString Then Exit Sub
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Set myRange = Selection.Find(what:=valuee, after:=Selection(1))
If myRange Is Nothing Then
MsgBox "no value"
Exit Sub
End If
myRange.Interior.ColorIndex = 3
st = myRange.Address(0, 0)
Do Until myRange Is Nothing
Set myRange = Selection.FindNext(after:=myRange)
If myRange.Address(0, 0) = st Then Exit Do
myRange.Interior.ColorIndex = 3
Loop
End Sub
尝试
如果myRange.value像“*”和value&“*”那么。equals是一个二进制比较。LIKE是一种模式匹配。如果myRange.value类似于“*”&value&“*”,请尝试,然后。equals是一个二进制比较。LIKE是一种模式匹配。如果myRange.value类似于“*”&value&“*”,请尝试,然后。equals是一个二进制比较。LIKE是一种模式匹配。如果myRange.value类似于“*”&value&“*”,请尝试,然后。equals是一个二进制比较。LIKE是一种模式匹配。谢谢!!很好用!为了使其不区分大小写,您可以使用InStr(1,myRange.value,value,vbTextCompare)谢谢!!很好用!为了使其不区分大小写,您可以使用InStr(1,myRange.value,value,vbTextCompare)谢谢!!很好用!为了使其不区分大小写,您可以使用InStr(1,myRange.value,value,vbTextCompare)谢谢!!很好用!为了使它不区分大小写,你可以使用InStr(1,myRange.value,value,vbTextCompare)你能给我一个.Find方法的例子吗?谢谢你的帮助!你能给我一个.Find方法的例子吗?谢谢你的帮助!你能给我一个.Find方法的例子吗?谢谢你的帮助!你能给我一个.Find方法的例子吗?谢谢你的帮助!