Home > Article > Software Tutorial > Excel VBA loop through columns
oh. Checked my previous code. It is estimated that it may be caused by errors in your iserror and vlookup results! ! !
Because there is a formula behind the vlookup generation, and the parameters provided to iserror are incorrect, it is caused by this.
I just converted it into a numerical format, and then applied iserror, and then it was ok.
My code is as follows:
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
So, you just need to split the code and convert it into numerical values.
Welcome to the If Software Changes Life group, let’s work together to improve work efficiency.
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 will return an error value when the data cannot be found, so it cannot be used directly
If you must use vlookup, please see the following code:
------------------------
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
The above is the detailed content of Excel VBA loop through columns. For more information, please follow other related articles on the PHP Chinese website!