Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1
Default VLOOKUP returns #N/A and causes VBA routine to halt

I'm an absolute newcomer to Excel 2007 VBA (Started on my first
project 24 hours ago).

I'm trying to parse some data I have downloaded. I use VLOOKUP to
search for specific strings. It works fine if the string is present,
but if the string is not present then VLOOKUP returns #N/A which seems
to cause the execution of my routine to be halted. I have to tried to
wrap IsNA() around VLOOKUP, but my routine is still halted. I have
also tried to add "On Error Resume Next" but that seems to cause the
following check (IsNA) to fail (i.e. #N/A is not detected). I assume
the #N/A value gets wiped out by the "On Error Resume Next Statement".
How do I get Execl to continue executing when #N/A is returned, but at
the same branch out if #N/A was returned?

Here is what I want to do: I want to search my downloaded data for a
specific string. If the string is present then I want to grap the
associated data (and store them somewhere). If the string is not
present then I want to go and search for the next string and the whole
thing repeats itself until I get thru all my patterns.

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default VLOOKUP returns #N/A and causes VBA routine to halt

If you use application.worksheetfunction.vlookup(), you have to code around
runtime errors.

Dim res as variant
on error resume next
res = application.worksheetfunction.vlookup(something, somerange,3, false)
if err.number < 0 then
res = "not found"
err.clear
end if
msgbox res

=======
I find that using application.vlookup easier to understand and use:

Dim res as variant
res = application.vlookup(something, somerange,3, false)
if isserror(res) then
res = "not found"
end if
msgbox res

=======
The same technique applies to the =match() worksheet function, too.


wrote:

I'm an absolute newcomer to Excel 2007 VBA (Started on my first
project 24 hours ago).

I'm trying to parse some data I have downloaded. I use VLOOKUP to
search for specific strings. It works fine if the string is present,
but if the string is not present then VLOOKUP returns #N/A which seems
to cause the execution of my routine to be halted. I have to tried to
wrap IsNA() around VLOOKUP, but my routine is still halted. I have
also tried to add "On Error Resume Next" but that seems to cause the
following check (IsNA) to fail (i.e. #N/A is not detected). I assume
the #N/A value gets wiped out by the "On Error Resume Next Statement".
How do I get Execl to continue executing when #N/A is returned, but at
the same branch out if #N/A was returned?

Here is what I want to do: I want to search my downloaded data for a
specific string. If the string is present then I want to grap the
associated data (and store them somewhere). If the string is not
present then I want to go and search for the next string and the whole
thing repeats itself until I get thru all my patterns.


--

Dave Peterson
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
No RETURN() or HALT() function found on macro sheet [email protected] Excel Discussion (Misc queries) 3 September 26th 06 03:35 PM
Vlookup returns a zero? Richard Excel Discussion (Misc queries) 3 June 21st 06 09:49 PM
VLookup returns #VALUE! BEEJAY Excel Worksheet Functions 2 September 8th 05 02:25 PM
vlookup returns 0.00 steve alcock Links and Linking in Excel 4 May 6th 05 12:47 AM
vlookup returns n/a Todd L. Excel Worksheet Functions 1 November 5th 04 09:05 PM


All times are GMT +1. The time now is 09:43 AM.

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"