VBA语句Cells.Find 和Cells.FindNext的用法

网站编辑
网站编辑
编辑
1211
文章
0
粉丝
互联网&数码 技术流评论51,760阅读模式

Vba中使用Cells.Find来查找某个字符串

用Cells.FindNext来查找下一个

具体用法如下文章源自原紫番博客-https://www.yuanzifan.com/4472.html

注意:以下代码必须写在模块中,不能写在活动单元格中  (下图所示,只有把代码创建在Modules之中,才能有效运行,不然会报错,不要问我为什么,我不会解释的。)文章源自原紫番博客-https://www.yuanzifan.com/4472.html

文章源自原紫番博客-https://www.yuanzifan.com/4472.html

首先,在活动页Sheet1中的任何两个单元格里填写 字符串Yuanzifan.com文章源自原紫番博客-https://www.yuanzifan.com/4472.html

然后,运行下列语句:文章源自原紫番博客-https://www.yuanzifan.com/4472.html

Sub Test()文章源自原紫番博客-https://www.yuanzifan.com/4472.html

Sheets("Sheet1").Select文章源自原紫番博客-https://www.yuanzifan.com/4472.html

Cells(1, 1).Select文章源自原紫番博客-https://www.yuanzifan.com/4472.html

Cells.Find(What:="Yuanzifan.com", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _文章源自原紫番博客-https://www.yuanzifan.com/4472.html

xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True, _文章源自原紫番博客-https://www.yuanzifan.com/4472.html

SearchFormat:=False).Activate

Cells.FindNext(After:=ActiveCell).Activate

Selection.Offset(0, 1).Activate

End Sub

你会发现,最后光标停留在后一个Yuanzifan.com之上。

Cell.finds就是查找某字符串,查到后就停止查找,而Cell.findnext则是继续查找,相当于”查找下一个”功能。

查找成功后,光标会停留在字符串所在单元格。

Active 和Print 语句

站长微信
扫码添加(注明来意)
weinxin
Yuanzifan99
微信号已复制
原梓番博客公众号
博客内容精选
weinxin
原梓番博客
公众号已复制
 

发表评论

匿名网友
确定

拖动滑块以完成验证