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

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
原梓番博客
 
    • Josephwrarl 4

      研究你的文章, 我看出, 世界很美。无限感谢 能量。 [url=https://iqvel.com/zh-Hans/a/%E4%BF%84%E7%BD%97%E6%96%AF/%E5%9F%BA%E6%96%AF%E6%B4%9B%E6%B2%83%E6%96%AF%E5%9F%BA%E5%9B%BD%E5%AE%B6%E5%85%AC%E5%9B%AD]自然保護[/url] 充满正能量的 素材! 现在想出发。

    发表评论

    匿名网友
    :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
    确定

    拖动滑块以完成验证