1、查找指定单元格中的指定内容
Sub findNext()
Dim StrFind As String
Dim Rng As Range
Dim FIndAddress As String
StrFind = InputBox("请输入要查找的值")
If Trim(StrFind) <> "" Then
With Sheet1.Range("A1:B2").Rows(2)
Set Rng = .Find(What:=StrFind, After:=.Cells(.Cells.Count), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
If Not Rng Is Nothing Then '如果不为空,记录下查到值的位置
FIndAddress = Rng.Address
Do
Rng.Interior.ColorIndex = 0 '将查到的单元格颜色自定义
Set Rng = .FindNext(Rng) '再次查找
Loop While Not Rng Is Nothing And Rng.Address <> FIndAddress '一直循环到刚才记录下的位置
End If
End With
End If
End Sub
网友评论