types不匹配错误VBA – 为什么?

我有一个基本的macros观,看着B列中的单元格,然后将“NA”放置在列C中的单元格的基础上,我正在寻找的标准。 我有一个types不匹配的错误,我不明白为什么。

Sub badURLs() Dim lr As Long ' Declare the variable lr = Range("B2:B23068").End(xlUp).Row ' Set the variable ' lr now contains the last used row in column A Application.ScreenUpdating = False For a = lr To 1 Step -1 If InStr(1, a, "bloomberg" Or "wiki" Or "hoovers", vbTextCompare) > 0 Then 'Compares for bloomberg, wiki, or hoovers. Enters loop if value is greater than 0 With Cells(a, 3) .NumberFormat = "General" .Value = "NA" End With End If Next a Application.ScreenUpdating = True End Sub 

不匹配错误发生在这里:

 With Cells(a, 3) 

你确定你在With Cells(a, 3)行上得到错误? 我想象你得到的If InStr行的错误,因为该行是完全无效的语法。 它应该是:

  If InStr(1, Cells(a, 3), "bloomberg", vbTextCompare) > 0 _ Or InStr(1, Cells(a, 3), "wiki", vbTextCompare) > 0 _ Or InStr(1, Cells(a, 3), "hoovers", vbTextCompare) > 0 Then 

尝试这个:

  With ActiveSheet.Cells(a, 3)