View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Rob van Gelder[_4_] Rob van Gelder[_4_] is offline
external usenet poster
 
Posts: 1,236
Default Array MATCH function for VBA

Tom, Thanks.

Guessed as much... still handy for 1D lookup.


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Tom Ogilvy" wrote in message
...
Not with match - it is the match worksheet function, so has the same
restriction of searching a single column or single row (or the vba
equivalent ex: 1D array for a 2D array like myarray(1 to n, 1 to 1)

See Alan's post.

--
regards,
Tom Ogilvy

Rob van Gelder wrote in message
...
Tom,

That's an amazing shortcut for quickly searching a 1D array. I like it.

Do you know if it's possible to search a 2D array that way?


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Tom Ogilvy" wrote in message
...
Dim dtVal as Date
dtVal = DataValue("01/22/2004")
res = application.Match(clng(dtVal),MyArray,0)

if not iserror(res) then
msgbox "Index is " & res - 1
end if

res will be 1 based. If your array is zero based, subtract 1

--
Regards,
Tom Ogilvy


ExcelMonkey wrote in

message
...
I have a 2d VBA array. It is 1 row and 10 columns. It is filled

with
dates. I want to return the position of a date variable within the
array. Similar to what I would do with a MATCH function in Excel.

How do you do this in VBA.


---
Message posted from http://www.ExcelForum.com/