Unable to get the VLookup property of the WorksheetFunction class

linxd

New Member
Joined
May 31, 2017
Messages
1
I have these codes

Code:
If Application.WorksheetFunction.VLookup(Cells(i, "AI").Value & Cells(i, "AH").Value, Sheets("WS rules").Range("D75:E284"), 2, 0) = "Y" Then
            If Cells(i, "O").Value = "2" Or Cells(i, "O").Value = "3" Or Cells(i, "O").Value = "4" Or Cells(i, "O").Value = "5" Or Cells(i, "O").Value = "R" Then
                Cells(i, "AT").Value = "Y"
            Else
                If Cells(i, "AS").Value < Application.WorksheetFunction.VLookup(Cells(i, "AG").Value & Left(Cells(i, "B").Value, 1), Sheets("WS rules").Range("F5:I64"), 3, 0) Then
                    Cells(i, "AT").Value = "Y"
                Else
                    Cells(i, "AT").Value = "N"
                End If
            End If
            
            
            If Application.WorksheetFunction.VLookup(Cells(i, "AI").Value & Cells(i, "AH").Value, Sheets("WS rules").Range("D75:E284"), 2, 0) = "Y" And Cells(i, "O").Value = "5" Then
                Cells(i, "AY").Value = "Y"
            Else
                If Cells(i, "AX").Value < Application.WorksheetFunction.VLookup(Cells(i, "AG").Value & Left(Cells(i, "B").Value, 1), Sheets("WS rules").Range("F5:I64"), 4, 0) Then
                    Cells(i, "AY").Value = "Y"
                Else
                    Cells(i, "AY").Value = "N"
                End If
            End If
            
        Else
            Cells(i, "AT").Value = "N"
        End If

Code:
If Application.WorksheetFunction.VLookup(Cells(i, "AG").Value & Left(Cells(i, "B"), 1), Sheets("WS rules").Range("F5:J64"), 5, False) = "Y" Then
            Cells(i, "AZ").Value = Cells(i, "AY").Value
        Else
            Cells(i, "AZ").Value = Cells(i, "AT").Value
        End If

But kept getting that error for VLookup. How do I fix the problem?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Welcome to the board.

That error is pretty much the equivilent of getting #N/A with a Vlookup formula in a cell.
Now we know that this error is sometimes expected.

The difference in VBA is that the error actually stops the code from running.

We can remove the worksheetfunction part, and assign the result of the vlookup to a variable.
Then test that variable for error in your If

Something like this
Rich (BB code):
MyVariable = Application.Vlookup(........)
If IsError(MyVariable) Then
     'Do nothing
Else
    If MyVariable = "Y" Then
        Cells(i, "AZ").Value = Cells(i, "AT").Value
    End If
End If
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top