IF FIND函数在vba中找不到任何东西

我目前正在自动执行以下步骤的手动过程:

1.提示用户打开数据文件并打开文件

2.插入4列

3.使用文件中已有的数据创build一个格式为“DD / MM / YYYY TEXT”的唯一string,其中text是一个variables

4.使用if语句来确定主数据文件中是否存在行

5.如果列d =“存在”中的值,则在主数据文件中查找string,并使用vlookup函数将数据从数据文件传输到主数据文件

6.Else(如果value =其他)然后插入一个新的行名称,然后使用vlookup函数将数据从数据文件传输到主文件

我的问题在于事实上,Unq.String有时/很less不是一个确切的匹配,所以通过使用FIND函数,它将返回消息:“我们找不到你要找的东西。search”

我的问题是,有没有办法在收到这个错误信息后,将数据粘贴到另一个名为“扫描”的选项卡上,然后再进入下一行? 我在我的代码中使用LOOP在步骤5和6,因为我将需要跳下每一行,但我不知道从哪里开始这个没有打破循环。

感谢您的帮助提前球员,让我知道如果你需要更多的信息关于上下文。

亚伦

谢谢

编辑评论解释我打算如何使用这个:

Dim ColumnD As String Dim SearchValue As String If ColumnD = "Exists" Then 'Find SearchValue in Master data sheet and vlookup 'ELSE Insert new row, add UNQ.String to New row then do the vlookup 'Loop untill using Rows.count + 1 and lastRow (Already declared) 

这个问题已经在这里探讨: 如何检测VBA Excel是否find了一些东西 。

基本上你可以设置一个范围variables到结果.find范围。 如果这个范围Nothing那么没有任何东西被返回,你可以以最适合你的方式回应用户。

编辑:根据OP的添加查询

 Sub findsomething() Dim foundsomething As Range Dim searchterm As String searchterm = "Search Term" Set foundsomething = Application.ActiveSheet.Find(What:="search term", After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _ False, SearchFormat:=False) If (Not foundsomething Is Nothing) And columnD = "Exists" Then ' Do something End If End Sub 

干杯,