Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
chg chg is offline
external usenet poster
 
Posts: 15
Default Find #Value Error

I'm trying to implement a simple search algorithm via vba.

My Problem is that i cannot seem to handle a #value error within vba

The UDF is called "FindBP"

Sometimes the Variable vIndex causes an #N/A Error, resulting in an
#vlaue error of the function.
I want to replace the vIndex calculation, every time it gives an
error.

My Implementation doesn't seem to work:

......
vIndex = WorksheetFunction.Match(vBP, rg, -1)
vCount = WorksheetFunction.Index(rg, vIndex)

If IsError(vCount) Then
vIndex = WorksheetFunction.Match(vBP, rg, 1)
FindBP = WorksheetFunction.Index(rg, vIndex)
Else
FindBP = WorksheetFunction.Index(rg, vIndex)
End If
.....

Any help is highly appreciated.

Thy in advance
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,045
Default Find #Value Error

On Tue, 26 Apr 2011 02:41:56 -0700 (PDT), chg wrote:

I'm trying to implement a simple search algorithm via vba.

My Problem is that i cannot seem to handle a #value error within vba

The UDF is called "FindBP"

Sometimes the Variable vIndex causes an #N/A Error, resulting in an
#vlaue error of the function.
I want to replace the vIndex calculation, every time it gives an
error.

My Implementation doesn't seem to work:

.....
vIndex = WorksheetFunction.Match(vBP, rg, -1)
vCount = WorksheetFunction.Index(rg, vIndex)

If IsError(vCount) Then
vIndex = WorksheetFunction.Match(vBP, rg, 1)
FindBP = WorksheetFunction.Index(rg, vIndex)
Else
FindBP = WorksheetFunction.Index(rg, vIndex)
End If
....

Any help is highly appreciated.

Thy in advance


You need to trap the error, and then handle it.

Take a look at help for On Error.

So something like:

....
On Error GoTo ErrorHandler

vIndex = ...
vCount = ...

On Error GoTo 0

.... <more of your code

Exit Sub

ErrorHandler:
... Error handling code
...
On error resume next

End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
chg chg is offline
external usenet poster
 
Posts: 15
Default Find #Value Error

So simple, damn I'm stupid.
Your my personal hero for today. Thanks!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,045
Default Find #Value Error

On Tue, 26 Apr 2011 03:40:17 -0700 (PDT), chg wrote:

So simple, damn I'm stupid.
Your my personal hero for today. Thanks!


Glad to help. Thanks for the feedback. Most things seem simple AFTER you figure them out, or have it pointed out. But until then, many things seem pretty complex.
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
Error dialog box meaning and how to find error Jeanne Excel Worksheet Functions 2 September 4th 08 04:59 AM
Find error!!!! Is there any other way to do this? [email protected] Excel Programming 11 September 14th 07 05:44 PM
help with this error-Compile error: cant find project or library JackR Excel Discussion (Misc queries) 2 June 10th 06 09:09 PM
change error message when no more for "find" in macro to find swyltm Excel Programming 1 January 13th 06 05:16 PM
Can someone find this error? jclark419[_3_] Excel Programming 4 July 27th 05 05:27 PM


All times are GMT +1. The time now is 03:06 PM.

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

About Us

"It's about Microsoft Excel"