Results 1 to 20 of 21

Thread: Solved: Supressing '#N/A' in WorksheetFunction.VLookup

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #14
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,476
    Location
    Small point first: You are missing a row
    [vba] ' Set lookup column & destination column in Destination worksheet
    Set rngLookup = destWksht.Range("A" & startingRow)
    Set rngLookup = rngLookup.Resize(rowSize:=lastRow - startingRow + 1)
    Set rngDestination = destWksht.Range("L" & startingRow).Resize(rowSize:=lastRow - startingRow + 1)
    [/vba]
    Main issue is here
    [vba] rngDestination = WorksheetFunction.VLookup(rngLookup, rngSource, i, 0)
    [/vba]
    rngLookup must be a single cell, as in the normal worksheet function.
    rngDestination is a block of cells. The same result will be written to each cell in that block. Looping each cell of rngLookup will keep overwriting previous results.

    I think this does what you are after (but tell me if I'm wrong!)

    I've also included an alternative coding which is more efficient, if I have the result correct.
    Attached Files Attached Files
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •