LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Search An Array in VBA

That means the value wasn't found. error 2042 is the same as #N/A
cvErr(xlErrNA)

from the immediate window:
? cvErr(xlErrNA)
Error 2042

In your sample code, you redim preserve your arrays twice, but you don't
change anything the second time, so not sure why you are doing it again
there (not that it should make a difference).

for instance, in my example I would normally do
Dim res as Variant
..
..
..
res = Application.VLookup(12, v, 5, False)
if iserror(res) then
msgbox "12 was not found"
Else
MsgBox "Value returned is " & res
End If

The only reason I used Redim in my example is that I declared my array as
dynamic

dim v() as Variant

I could have skipped the Redim if I did

Dim v(1 To 20, 1 To 5) as Variant

so there is nothing particularly pertinent with regard to using Redim in the
example. Most of the example was spend building up a dummy array so I could
demo that Vlookup worked.

Anyway, a common problem is that a textbox produces a string value. Even if
I entered 123 in the textbox, it would return "123" (a string with 3
characters that happend to be numerals). However, if my data contains 123
stored as a number, then "123" < 123 and vlookup would fail. This doesn't
appear to be your problem because you say you are searching for "tie4ch",
which is clearly text. Since you are looking for an exact match, any
possibility the search term might have a space or two appended on the end
"tie4ch " instead of "tie4ch"?

--
Regards,
Tom Ogilvy



"Dean Hinson" wrote in message
...
Tom,
I figured out the type mismatch but now I am getting an error 2042 from

the
VLOOKUP. What is that?

"Dean Hinson" wrote:

Hello,

I have a multidimensional array that is sorted on the first column and

was
trying to use the VLOOKUP to search for particular entries. VLOOKUP

doesn't
seem to reconize arrays. Has anybody been able to incorporate a faster
search other than scanning the array by looping through iterative times?

Any help is appreciated.

Dean.



 
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
array search Luke Excel Worksheet Functions 8 February 2nd 09 08:25 AM
Search for reference in an array DoubleZ Excel Discussion (Misc queries) 4 November 7th 08 10:55 PM
search array jchick0909 Excel Worksheet Functions 3 October 5th 07 07:25 PM
SEARCH EXCEL ARRAY FOR NON-VOIDS AND ENTER INTO ANOTHER ARRAY, ROSE THE RED Excel Programming 1 December 31st 04 06:01 PM
Search an array [email protected] Excel Programming 3 October 21st 03 08:47 PM


All times are GMT +1. The time now is 06:40 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"