vba - 查找“Cells.Find”函数的单元格引用
问题描述
我正在使用下面的代码来查找用户搜索的值(“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”的值总是空白,我希望有人知道找到对找到的单元格的引用的方法?
解决方案
为了找到地址,你可以这样做
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
推荐阅读
- c# - C# - 如何在线临时流式传输文件以访问 URL
- php - 使用 Timber for WordPress 时,如何从帖子类型声明 PHP var 以进行 for 循环?
- html - 将鼠标悬停在文本上时如何防止文本更改?
- node.js - fs.createReadStream 未定义
- c - 如何在 Windows 和 macOS 上检测 C 中的 USB 串行端口连接?
- angular - 我可以为每个用户从 localStorage 中删除一个项目吗?
- random - 类似 MWC 的随机生成器的维度是多少?
- java - 如何为单个 Spring Boot 应用程序创建两个日志文件
- python - 时间戳到日期时间的转换结果在 python 中为 2082
- postgresql - 如何在 PostgreSQL 中提取表的唯一列的名称?