十宗罪人物原型:使用Find方法查找单元格
来源:百度文库 编辑:中财网 时间:2024/05/03 05:45:10
代码:
#001 Sub RngFind()
#002 Dim StrFind As String
#003 Dim Rng As Range
#004 StrFind = InputBox("请输入要查找的值:")
#005 If Trim(StrFind) <> "" Then
#006 With Sheet1.Range("A:A")
#007 Set Rng = .Find(What:=StrFind, _
#008 After:=.Cells(.Cells.Count), _
#009 LookIn:=xlValues, _
#010 LookAt:=xlWhole, _
#011 SearchOrder:=xlByRows, _
#012 SearchDirection:=xlNext, _
#013 MatchCase:=False)
#014 If Not Rng Is Nothing Then
#015 Application.Goto Rng, True
#016 Else
#017 MsgBox "没有找到该单元格!"
#018 End If
#019 End With
#020 End If
#021 End Sub
代码解析:expression_r_r.Find(What, After, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase, MatchByte, SerchFormat)
代码:
#001 Sub RngFindNext()
#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