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?????