Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Problem with "On error resume next" with "custom VLookup"

I have this:

Function FN(Table As Range, Val1 As String)
Dim i As Integer
On Error Resume Next
For i = 1 To Table.Rows.Count
If Not WorksheetFunction.IsError(WorksheetFunction.Find(V al1, Table.Cells(i, 1), 1)) Then
FN = Table.Cells(i, 2)
End If
Next i
End Function

which always returns the value of second column in the last! row of the range
provided in the argument; if I leave out the "On error resume next" I always get #Value returned. I am sure that it only does what I tell it to do - only I don't know how to fix it.

Thanks a lot in advance !


Morten
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 968
Default Problem with "On error resume next" with "custom VLookup"

Hi Morten,

try something like this, assuming that table is not sorted

Public Function FN(Table As Range, Val1 As String)
Dim vRow As variant

FN=cverr(XlerrNA)
On Error goto fail
vRow=application.Match(Val1, Table.columns(1), 0)
if not iserror(vrow) then
FN = Table.Cells(clng(vRow), 2)
End If
Fail:

End Function


Charles
______________________
Decision Models
The Excel Calculation Site.
www.DecisionModels.com

"Factivator" wrote in message
...
I have this:

Function FN(Table As Range, Val1 As String)
Dim i As Integer
On Error Resume Next
For i = 1 To Table.Rows.Count
If Not WorksheetFunction.IsError(WorksheetFunction.Find(V al1,

Table.Cells(i, 1), 1)) Then
FN = Table.Cells(i, 2)
End If
Next i
End Function

which always returns the value of second column in the last! row of the

range
provided in the argument; if I leave out the "On error resume next" I

always get #Value returned. I am sure that it only does what I tell it to
do - only I don't know how to fix it.

Thanks a lot in advance !


Morten



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
correct syntax for nesting "if", "and", and "vlookup"....if possib Christine Excel Worksheet Functions 4 January 2nd 09 10:43 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM


All times are GMT +1. The time now is 11:17 AM.

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"