我们可以从range.find的结果中得到什么其他选项?

Jay*_*Jay 2 excel vba excel-vba

在Excel VBA中,当您执行range.find时,您可以获取result.address.我们可以从结果中获得除.address之外的其他选项吗?我找不到用于在Google上搜索的字词.如果我们能得到像result.col这样的其他信息会很好.其他选项不会在代码窗口中显示结果.

Sid*_*out 5

您可以使用结果来完成剩下的工作.例如,如果您使用下面的代码,如果找到匹配项,那么您可以获得其余的详细信息.见截图.

Sub Sample()
    Dim oSht As Worksheet
    Dim strSearch As String
    Dim aCell As Range

    On Error GoTo Err

    '~~> Set this to the relevant sheet
    Set oSht = Sheets("Sheet1")

    '~~> Search String
    strSearch = "Sid"

    '~~> Do the Find
    Set aCell = oSht.Cells.Find(What:=strSearch, LookIn:=xlFormulas, _
    LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False)

    '~~> If Found
    If Not aCell Is Nothing Then
        Debug.Print aCell.Row      '<~~ Give the Row
        Debug.Print aCell.Column   '<~~ Gives the Column
        '~~> AND SO ON
    End If
    Exit Sub
Err:
    MsgBox Err.Description
End Sub
Run Code Online (Sandbox Code Playgroud)

截图

在此输入图像描述

小费

你可能会发现是一个有趣的读物.

  • Range.Find()返回一个范围对象.如果你使用Sid的技术并将`aCell`指定为`.Find()`方法的结果,那么你就可以使用它,好像它是一个Range对象 - 事实上,它是一个Range对象:)和+用于Sid的一个很好的视觉解释 (2认同)