+ Reply to Thread
Results 1 to 12 of 12

VLOOKUP run-time error

  1. #1
    Registered User
    Join Date
    08-02-2010
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    55

    Talking VLOOKUP run-time error

    Hello guys!

    I've tried to use VLOOKUP function in order to add Department for each Item that I have in my workbook. But, the message box keep prompting "Run-time error '1004': Unable to get Vlookup property in the Worksheet function class" when I run this code:


    Please Login or Register  to view this content.
    I just can't detect where the mistake that I have done with this vlookup formula. Can anyone give some help?

    Thanks.
    Attached Files Attached Files
    Last edited by isabella; 10-13-2010 at 10:14 PM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,613

    Re: VLOOKUP run-time error

    1. You are parsing through cells in column A
    MyCell.Offset(0, -1).Value is trying to put a value in the column to the left of column A which does not exist
    2. Column A is empty (at least in the sheet you provided), therefore,
    Val(Mid(MyCell, 2, 1)) fails
    3. Notice that when your IF condition is TRUE, i.e., the cell is blank, then you try to use the above function to get the value of the middle of an empty cell.

    4. Sheets(2) should be written Sheets("department") to avoid confusion. You notice in VBA project explorer that you have Sheet1(SVC) & Sheet5(Department) so that it's not clear which is referred to by Sheets(2)
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    08-02-2010
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    55

    Re: VLOOKUP run-time error

    Thanks protonLeah!

    I have change my code to this:
    Please Login or Register  to view this content.
    It works for my first vlookup condition, not for the second one.
    How can I modify that code to achieve the second vlookup condition? (For 4 item from bottom.)

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,613

    Re: VLOOKUP run-time error

    You have two statements in your IF condition:
    MyCell.Offset(0, -2).Value = WorksheetFunction.VLookup(Val(Mid(MyCell, 2, 1)), Sheets("Department").Range("ONERNG"), 2, False)
    MyCell.Offset(0, -2).Value = WorksheetFunction.VLookup(Val(Mid(MyCell, 2, 2)), Sheets("Department").Range("TWORNG"), 2, False)
    Both statements are writing to the same cell so that only the results of the last statement are preserved since it overwrites whatever is written by the first statement.
    What are you trying to do with those two statements?

  5. #5
    Registered User
    Join Date
    08-02-2010
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    55

    Talking Re: VLOOKUP run-time error

    I see.

    Actually, I want to add department name on Department Name column. What I want to do is like this:

    Please Login or Register  to view this content.
    For better understanding, you can refer the attachment on "Department" sheet.

    Your help are most welcome.
    Thanks!

    Last edited by isabella; 10-12-2010 at 03:58 AM.

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: VLOOKUP run-time error

    Why don't you use formulae in the first place ?

    A6: =Vlookup(Mid(C6,2,1),onerng,2,false)

    or in VBA
    Please Login or Register  to view this content.



  7. #7
    Registered User
    Join Date
    08-02-2010
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    55

    Re: VLOOKUP run-time error

    Thanks snb.

    I already editted your code to this:

    Please Login or Register  to view this content.
    But, the message box keep prompting "Object variable or With block variable not set".
    Am I missing something?

  8. #8
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: VLOOKUP run-time error

    do not edit...

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    08-02-2010
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    55

    Re: VLOOKUP run-time error

    Thanks, but it still did not work.
    Can you attach the workbook that you have tested?

    Thank you very much!


  10. #10
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,613

    Re: VLOOKUP run-time error

    You need to look at the second character of the invoice and test for your conditions:
    Condition 1: the character is 1 or 5 or 6 therefore lookup a name from the first table
    Condition 2: the second character is a 3 therefore lookup the name from the second table using the second and third characters of the invoice
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    08-02-2010
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    55

    Re: VLOOKUP run-time error

    Thank you very much protonLeah.You have reveal the logic to me.

    Thanks again!

  12. #12
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: VLOOKUP run-time error

    or
    Please Login or Register  to view this content.

+ 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.6.0 RC 1