哦。检查了我以前的代码。估计可能是你的iserror和与vlookup后面结果的错误造成的!!!
因为vlookup生成的后面有公式存在,而提供给iserror的参数错误,导致的。
我当初就是再把它转成数值格式的,然后再应用iserror,后面就ok了。
我的代码如下:
For i = 2 To module_number - 1
Range("C" & i).Select: ActiveCell.Value = ActiveCell.Value: If IsError(ActiveCell.Value) Then ActiveCell.Value = 0: Module_wrong = 1: iublink = Cells(ActiveCell.Row, 1): Exit Sub
Next
所以,你只要把代码拆分开,然后转换成数值就ok了。
欢迎假如软件改变生活群,大家一起努力,提升工作效率。
Public Sub aaaa()
Dim x As String, w As String
Dim z As Long
x = "Y"
w = "N"
For z = 2 To 10000
If Cells(z, 1) "" Then
Cells(z, 2).FormulaR1C1 = "=IF(ISNUMBER(VLOOKUP(RC[-1],C[1],1,0)),""" & x & """,""" & w & """)"
Cells(z, 2).Value = Cells(z, 2).Value
End If
Next
End Sub
----------------
vlookup在找不到数据时会返回错误值,所以不能直接使用
如果非要用vlookup,请看下面的代码:
---------------------
Public Sub dsadsa()
Dim x As String, w As String
Dim z As Long, u As Variant
Dim o As Range: Set o = Worksheets("Sheet1").Range("c:c")
x = "Y"
w = "N"
For z = 2 To 6
If Cells(z, 1) "" Then
On Error Resume Next
u = Application.WorksheetFunction.VLookup(Sheets("sheet1").Cells(z, 1), o, 1, False)
If Err.Number = 0 Then
Cells(z, 2) = x
Else
Cells(z, 2) = w
End If
Err.Clear
End If
Next
End Sub
以上是Excel VBA循环遍历列的详细内容。更多信息请关注PHP中文网其他相关文章!