我有一个基本的宏,它是在B列中查看单元格,然后根据我正在查找的条件将“NA”放置在C列中单元格的旁边。我有一个类型不匹配的错误,我不明白为什么。类型不匹配错误VBA - 为什么?
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)
是否有可能在'lr'是永远是0?第一次运行'For'循环会发生吗?另外,在你的sub的最顶端添加Option Option,并且添加Dim a as Long(或者一个快捷方式是Dim a&')。 – BruceWayne
当程序遇到错误时,“a”的值是多少?将鼠标悬停在变量“a”上以查看它是什么。我还注意到,你的lr(lastrow)变量是从B列中取出的,而不是A列中的,正如你的评论所暗示的那样。检查您感兴趣的列。 –