' On Error Resume Next 'Turn off error handling
Set mf = Selection.Find(What:=FindText, after:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False) 'search and find my opnumber
On Error GoTo 0 'turn back on default error handeling
If mf Is Nothing Then
MyActiveSheet.Activate
With mf
.Interior.ColorIndex = 27
End With
GoTo skipit
Else
mf.Activate
End If
我试图突出显示我搜索未找到的所有细胞黄色。出于某种原因,我似乎无法让它发挥作用。
答案 0 :(得分:0)
突出显示搜索
中搜索找不到的内容
试试这段代码:
Sub test()
Dim mf As Range
Dim sAddr As String
Dim FindText As String
FindText = "test"
With Selection
.Interior.ColorIndex = 27
Set mf = .Find(What:=FindText, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
If Not mf Is Nothing Then
sAddr = mf.Address
Do
mf.Interior.ColorIndex = xlNone
Set mf = .FindNext(mf)
If mf Is Nothing Then Exit Do
Loop While mf.Address <> sAddr
End If
End With
End Sub
主要思想是用黄色突出显示整个选择,然后从找到FindText
的所有单元格中删除突出显示。