+ Reply to Thread
Results 1 to 2 of 2

Vlooup offset

  1. #1
    Registered User
    Join Date
    08-26-2008
    Location
    Canada
    Posts
    11

    Vlooup offset

    Hi, please help with this

    I've found some code to create a user define function
    Function Lookup_Occurence(To_find, Table_array As Range, _
    Look_in_col As Long, Offset_col, Occurrence As Long, _
    Optional Case_sensitive As Boolean, Optional Part_cell_match As Boolean)

    Dim lLoop As Long
    Dim rFound As Range
    Dim xlLook As XlLookAt
    Dim lOcCheck As Long



    If Part_cell_match = False Then
    xlLook = xlWhole
    Else
    xlLook = xlPart
    End If

    Set rFound = Table_array.Columns(Look_in_col).Cells(1, 1)

    On Error Resume Next
    lOcCheck = WorksheetFunction.CountIf _
    (Table_array.Columns(Look_in_col), To_find)

    If lOcCheck < Occurrence Then
    Lookup_Occurence = vbNullString
    Else
    For lLoop = 1 To Occurrence
    Set rFound = Table_array.Columns(Look_in_col).Find _
    (What:=To_find, After:=rFound, LookAt:=xlLook, LookIn:=xlValues, _
    MatchCase:=Case_sensitive)
    Next lLoop

    On Error GoTo 0

    Lookup_Occurence = rFound.Offset(0, Offset_col)


    End If



    End Function

    This functions lets you choose any offset to find in any column any occurence in an array, but it won't return the correct range, it only returns the first cell of the selected array (Table_Array).

    For example, if To_find="x", Table_Array=A1:C3, Look_in_col=2, Offset_col=-1, Occurrence=1, assuming the value exists, it should return the value of the range A2, however it would always returne the value of the range A1

    Anyone knows how to fix this?????

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: Vlooup offset

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

+ 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