查找“Cells.Find”函数的单元格引用

问题描述 投票:1回答:1

我正在使用下面的代码来查找用户搜索到的值(“strFindWhat”),该值被输入到单元格中,然后按下按钮以触发此子。系统包含一长串数据,用户将搜索产品编号,以便他们可以快速查看相应的批号。

Cells.Find(What:=strFindWhat, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
    :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
    False).Select

我想要做的是找到对此代码找到的单元格的引用。因此,我可以更改找到的单元格的颜色或行,以突出显示他们需要的数据,以便他们可以更清楚地看到它。我通过使整个函数等于变量来尝试显而易见的事情:

foundCell = Cells.Find(What:=strFindWhat, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
    :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
    False).Select

“foundCell”的值总是空白,我希望有人知道找到找到的单元格的引用的方法吗?

excel vba excel-vba
1个回答
4
投票

为了找到你可以做的那样的地址

Dim foundCell As Range
    Set foundCell = Cells.Find(What:=strFindWhat, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
             :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
                        False)

    If Not (foundCell Is Nothing) Then
        Debug.Print foundCell.Address
    End If
© www.soinside.com 2019 - 2024. All rights reserved.