Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Lookup problems

Anyone who'd encountered problems when they encapsulate VLookup or
HLookup? I'm trying to write a generalized lookup function which I can
control the direction of lookup through an argument but when I step the code
through, it stops execution at the line of .VLookup/ .HLookup. It does not
halt the program flow and execute all cells that uses this formula with
#VALUE! result.

Public Function MyGeneralLookUp(Direction As Long, Key As Range, TableName
As Range, StartPoint As Long, Match As Boolean) As String
MyGeneralLookUp = ""
Application.EnableEvents = False
' Some key to search with
If (Not (CStr(Key.Value) = "")) Then
' Initialize an offset table so that data can be retrieved from the
correct position
Call CreateOffsetTable
' Calculate offset distance off StartPoint
Offset = SeekOffset(OffsetTag)
With Application.WorksheetFunction
' Enforce looking up exact key
Match = (Not Match)
' Lookup value depending on direction
Select Case Direction
Case HDir
FetchedResult = .VLookup(Key, TableName, Offset, Match)
Case VDir
FetchedResult = .HLookup(Key, TableName, Offset, Match)
End Select
' No error from lookup & result is either a text or number
If ((Not .IsError(FetchedResult)) And _
(((.IsText(FetchedResult)) Or (.IsNumber(FetchedResult)))) _
) Then
MyGeneralLookUp = FetchedResult
End If
End With
End If
Application.EnableEvents = True
End Function

Would appreciate any suggestions or pointers! Cheers!
_______
cLiffordiL


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default Lookup problems

What do CreateOffsetTable and SeekOffset do? (include code)
What are the types and values of OffsetTag, Offset, HDir, Vdir (especially Offset, since it is part of the error formula)
In the immediate window, Application.WorksheetFunction.Vlookup doesn't work, but Application.Vlookup does.

--
Kind regards,

Niek Otten


"cLiffordiL" wrote in message ...
| Anyone who'd encountered problems when they encapsulate VLookup or
| HLookup? I'm trying to write a generalized lookup function which I can
| control the direction of lookup through an argument but when I step the code
| through, it stops execution at the line of .VLookup/ .HLookup. It does not
| halt the program flow and execute all cells that uses this formula with
| #VALUE! result.
|
| Public Function MyGeneralLookUp(Direction As Long, Key As Range, TableName
| As Range, StartPoint As Long, Match As Boolean) As String
| MyGeneralLookUp = ""
| Application.EnableEvents = False
| ' Some key to search with
| If (Not (CStr(Key.Value) = "")) Then
| ' Initialize an offset table so that data can be retrieved from the
| correct position
| Call CreateOffsetTable
| ' Calculate offset distance off StartPoint
| Offset = SeekOffset(OffsetTag)
| With Application.WorksheetFunction
| ' Enforce looking up exact key
| Match = (Not Match)
| ' Lookup value depending on direction
| Select Case Direction
| Case HDir
| FetchedResult = .VLookup(Key, TableName, Offset, Match)
| Case VDir
| FetchedResult = .HLookup(Key, TableName, Offset, Match)
| End Select
| ' No error from lookup & result is either a text or number
| If ((Not .IsError(FetchedResult)) And _
| (((.IsText(FetchedResult)) Or (.IsNumber(FetchedResult)))) _
| ) Then
| MyGeneralLookUp = FetchedResult
| End If
| End With
| End If
| Application.EnableEvents = True
| End Function
|
| Would appreciate any suggestions or pointers! Cheers!
| _______
| cLiffordiL
|
|


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
am having lookup problems, please help drwainscott Excel Discussion (Misc queries) 1 August 15th 08 02:44 AM
LOOKUP problems Martin Ledgard Excel Worksheet Functions 3 September 7th 07 11:42 PM
Problems with LOOKUP ExcelMonkey Excel Worksheet Functions 7 January 10th 07 06:27 PM
v-lookup problems DF Excel Worksheet Functions 0 June 6th 06 10:36 PM
Lookup problems JaB Excel Worksheet Functions 2 September 22nd 05 12:33 PM


All times are GMT +1. The time now is 08:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"