VBA使用与通配符相似的运算符

我试图比较地址数据。 我当前的macros比较两列,并input“丢弃的数据”,当他们不匹配。 问题是大量的这些值没有被丢弃,而是被整合到另一个单元中。 我想改变我的macros,以便能够find使用VBA的像运算符的缺失值。 例如在“9825频谱医学馆3”中会发现“Bldg 3”。 我能够从网上查看这些代码,但我不确定Range("C65536")是在select什么范围。

编辑:我看到人们build议我使用Instr函数似乎做我想做的事情。 我不知道如何让它在我的macros中工作/让它引用正确的单元格。 它也(从我的理解)返回值等于发现的字符数。 所以在我给出的例子中,如果包含空格,将返回值6。

 Sub droppeddata() Application.ScreenUpdating = False lr = Range("C65536").End(xlUp).Row For a = lr To 1 Step -1 If Not IsEmpty(Cells(a, 13).Value) And IsEmpty(Cells(a, 19)) Then Cells(a, 10).Select Selection.NumberFormat = "General" ActiveCell.FormulaR1C1 = "N" Cells(a, 11).Select Selection.NumberFormat = "General" ActiveCell.FormulaR1C1 = "Dropped Data" End If Next a Application.ScreenUpdating = True End Sub 

您当前的macros不会以您想要的方式进行比较,只是检查两列是否为空。

你对于你所要做的事情并没有特别的了解,所以这段代码是用一些猜测来完成的:

 Sub droppeddata() Dim lr As Long ' Declare the variable lr = Range("C65536").End(xlUp).Row ' Set the variable ' lr now contains the last used row in column C Application.ScreenUpdating = False For a = lr To 1 Step -1 If IsEmpty(Cells(a, 19)) Or InStr(1, Cells(a, 13).Value, Cells(a, 19).Value, vbTextCompare) > 0 Then ' If Cells(a, 19) is empty OR ' Search Cells(a, 13) for the value contained in Cells(a, 19) ' If INSTR returns a match greater than 0, it means the string we're looking for is present ' Enter the loop if either condition is true ' In this section, avoiding SELECT is preferable. Working directly on the ranges is good. With Cells(a, 10) .NumberFormat = "General" .Value = "N" End With With Cells(a, 11) .NumberFormat = "General" .Value = "Dropped Data" End With End If Next a Application.ScreenUpdating = True End Sub 

改变范围/细胞到你的需要 – 目前的不是为了工作,我只是根据你现有的代码猜测。