VBA:如何找到包含给定范围内的子字符串的单元格?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1753446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 11:00:46  来源:igfitidea点击:

VBA: How do I find a cell containing a substring in a given range?

excelvba

提问by hi.

Say I have a range of data from A1:Y55 containg data like "123 UID"

假设我有来自 A1:Y55 的一系列数据,其中包含诸如“123 UID”之类的数据

I am looking for a unique substring (in this case, the UID) in that range, how do I do this?

我正在寻找该范围内的唯一子字符串(在本例中为 UID),我该怎么做?

回答by Irwin M. Fletcher

You can do this with the following code.

您可以使用以下代码执行此操作。

On Error Resume Next

Range("A1:Y55").Find(What:="UID", After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Activate

The error statement will allow the program to continue if it does not find any matches.

如果没有找到任何匹配项,错误语句将允许程序继续。