2

在 Excel VBA 中,当您执行 range.find 时,您可以获得 result.address。除了 .address 我们可以从结果中获得任何其他选项吗?我找不到用于在 Google 上搜索的字词。如果我们能得到其他信息,比如 result.col 之类的,那就太好了。结果的代码窗口中不会显示其他选项。

4

1 回答 1

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

截屏

在此处输入图像描述

小费

您可能会发现是一本有趣的书。

于 2013-09-18T06:27:02.077 回答