jeudi 11 février 2021

Application-defined or object Defined error on Vlookup & IF statement

Hello Friends and Community,

I have been getting a VBA error with my code "Application-defined or object defined error'

Here is my code

Sub RSData()
Dim Column6 As Integer
Dim RowX As Integer
Dim EndofRow As Integer
EndofRow = Cells(Rows.Count, 2).End(xlUp).Row
For RowX = 14 To EndofRow
If Cells(RowX, 12) = "RS" Then
    For Column6 = 13 To 34
    Cells(RowX, Column6) = Application.WorksheetFunction.VLookup(Cells(RowX, 11), Worksheets("Base Data_RS").Columns("F:AH"), Column6 - 11, 0)
    Next Column6
Else: Cells(RowX, Column6) = Null
End If
Next RowX
End Sub

The weird thing is my previous code which is almost the same as this one runs fine, the only difference is the sheet that I am vlooking up agasint to, and the if criteria. Here is the previous code that works fine
And the error line happens in ' Else: Cells(RowX, Column6) = Null'
Any help will be greatly appreciated!

Sub CRSData()
Dim Column6 As Integer
Dim RowX As Integer
Dim EndofRow As Integer
EndofRow = Cells(Rows.Count, 2).End(xlUp).Row
For RowX = 14 To EndofRow
If Cells(RowX, 12) = "CRS" Then
    For Column6 = 13 To 34
    Cells(RowX, Column6) = Application.WorksheetFunction.VLookup(Cells(RowX, 11), Worksheets("Base Data_CRS").Columns("F:AH"), Column6 - 11, 0)
    Next Column6
Else: Cells(RowX, Column6) = Null
End If
Next RowX
End Sub

Aucun commentaire:

Enregistrer un commentaire