#001 Sub RngFindNext() ‘在A列查找InputBox对话框输入的值,将查到的单元格底色设成黄色
#002 Dim StrFind As String
#003 Dim Rng As Range
#004 Dim FindAddress As String
#005 StrFind = InputBox("请输入要查找的值:")
#006 If Trim(StrFind) <> "" Then
#007 With Sheet1.Range("A:A")
#008 Set Rng = .Find(What:=StrFind, _
#009 After:=.Cells(.Cells.Count), _
#010 LookIn:=xlValues,_
#011 LookAt:=xlWhole,_
#012 SearchOrder:=xlByRows, _
#013 SearchDirection:=xlNext, _
#014 MatchCase:=False)
#015 If Not Rng Is Nothing Then
#016 FindAddress = Rng.Address
#017 Do
#018 Rng.Interior.ColorIndex = 6
#019 Set Rng = .FindNext(Rng)
#020 Loop While Not Rng Is NothingAnd Rng.Address <> FindAddress
#021 End If
#022 End With
#023 End If
#024 End Sub
|