• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA VLOOKUP ERROR

AhmedAbbas

New Member
Appreciate your guidance in looking and telling me what is wrong in the code below

Sub acc()
Dim I As Integer
Dim AA As Integer
Dim B As Integer

AA = 16
B = (Range("b16").End(xlDown).Row)
For I = AA To B
Range("J" & I).Value = Application.WorksheetFunction.If(Range("P" & I).Value <> 0, Application.WorksheetFunction.VLookup(Range("B" & I), Sheets("ACC").Range("B2:C5"), 2, False), "")
Next I

End Sub


_____________________________________________________________

Post Moved by Moderator

.
 
Last edited by a moderator:
Replace this part:

Code:
For I = AA To B
Range("J" & I).Value = Application.WorksheetFunction.If(Range("P" & I).Value <> 0, Application.WorksheetFunction.VLookup(Range("B" & I), Sheets("ACC").Range("B2:C5"), 2, False), "")
Next I

with this:

Code:
For I = AA To B
If Range("P" & I).Value <> 0 Then
Range("J" & I).Value2 = Application.VLookup(Range("B" & I), Sheets("ACC").Range("B2:C5"), 2, False)
Else
Range("J" & I).Value = vbnullstring
End If
Next I
 
My sincere apologies I realized that the mistake was from my end as I was unable to put the correct code when working on offset formula. I again sincerely apologies for the inconvenience I caused and look forward for your guidance from both of you. Thanks
 
Back
Top