哦。檢查了我以前的程式碼。估計可能是你的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 Longx = "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中文網其他相關文章!