+ Reply to Thread
Results 1 to 6 of 6

Thread: Worksheet Functions in vba

  1. #1
    Registered User
    Join Date
    08-16-2010
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    23

    Worksheet Functions in vba

    I am using the following statement

    if worksheetfunction.iserror(worksheetfunction.vlookup(sheet1.cells(i,j).value,sheet2.range("range1"),2,0)) = true then

    can you please whether this is legal... my vba compiler is crashing when i am trying this

  2. #2
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: Worksheet Functions in vba

    Assuming i,j & range1 are all valid then perhaps:

    If IsError(Application.Vlookup(sheet1.Cells(i,j).value,sheet2.range("range1"),2,0)) Then

  3. #3
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274

    Re: Worksheet Functions in vba

    There's nothing wrong with the syntax itself, assuming the sheets exist and the variables are correct.

  4. #4
    Registered User
    Join Date
    08-16-2010
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: Worksheet Functions in vba

    How come then i am getting the following error

    unable to get vlookup property of worksheetfunction class

  5. #5
    Registered User
    Join Date
    08-16-2010
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: Worksheet Functions in vba

    @DonkeyoTe..

    Thanks for the tip..

    works like a charm

  6. #6
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274

    Re: Worksheet Functions in vba

    I thought you were getting a compile error, not a runtime one. The issue, as solved by DO, is that the WorksheetFunction.VLookup returns a runtime error, not an error value, if the value is not found in the table. Using Application.Vlookup returns an error value instead.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0