Consulting

Results 1 to 4 of 4

Thread: VBA VLOOKUP always returning zero.

  1. #1

    VBA VLOOKUP always returning zero.

    Hi,


    am using below function and always getting value zero for .
    i even tried changing cell formats for datarange, when i do that i get 13 type mismatch error. please help.


    If Trim(CStr(TextBox_itemcode.Text)) <> "" Then
    myitval = mylookup(Trim(CStr(TextBox_itemcode.Text)))
    Worksheets("SALES").Activate
    Range("amt_tot").Rows(ZeileA).Value = myitval
    Else
    Range("amt_tot").Rows(ZeileA).Value = "9999.99"
    End If

    Function mylookup(itemcode As String) As Double
    Dim myrange As Range
    Dim myvalue As Double
    Set myrange = Worksheets("Items sales").Range("G24:F1000")
    Worksheets("Items sales").Activate
    myitval = [Application.WorksheetFunction.SVERWEIS(itemcode, myrange, 5, False)]
    If IsError(myvalue) = True Then
    myvalue = 9999.99
    End If
    End Function

    please help.
    if possible also please suggest me how to convert this vlookup into index match.
    Last edited by Paul_Hossler; 06-27-2018 at 07:43 AM. Reason: Added CODE tags

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,873
    Note regarding these two lines:
    Set myrange = Worksheets("Items sales").Range("G24:F1000")
    myitval = [Application.WorksheetFunction.SVERWEIS(itemcode, myrange, 5, False)]
    that SWEREIS (aka VLOOKUP) is looking in the first column (column F) of a 2 column range (F24:G1000) and trying to return something from the 5th column of that 2 column range.
    I note also that you've used TRIM and you're looking for an Exact match; are you sure column F also contains no extra spaces?
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Thanks everyone for the quick help. its fixed.

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,873
    Quote Originally Posted by papermonkey View Post
    Thanks everyone for the quick help. its fixed.
    That was a month ago.
    Oh, it's because more help is needed.

Posting Permissions

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