Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 16
Default Finding the Location within an Array

Hi All,

Thanks to this Group I was provided a snipit of code to find out is a
value is within my Array:-
If Not IsError(Application.Match(some_value, myArray,0)) Then
Do somthing
else
Do somthing else
End If

This works Great Thank You.

Is it possible to find out the location of the value without having to
loop through each entry?

Many Thanks

Mark
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Finding the Location within an Array

dim res as variant
res = application.match(some_value, myArray,0)
if iserror(res) then
'no match
else
msgbox res
end if



Sh0t2bts wrote:

Hi All,

Thanks to this Group I was provided a snipit of code to find out is a
value is within my Array:-
If Not IsError(Application.Match(some_value, myArray,0)) Then
Do somthing
else
Do somthing else
End If

This works Great Thank You.

Is it possible to find out the location of the value without having to
loop through each entry?

Many Thanks

Mark


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,651
Default Finding the Location within an Array

On Wed, 5 Dec 2007 03:45:33 -0800 (PST), Sh0t2bts wrote:

Hi All,

Thanks to this Group I was provided a snipit of code to find out is a
value is within my Array:-
If Not IsError(Application.Match(some_value, myArray,0)) Then
Do somthing
else
Do somthing else
End If

This works Great Thank You.

Is it possible to find out the location of the value without having to
loop through each entry?

Many Thanks

Mark


You merely return the result of your Match function.

=====================================
Option Explicit
Sub foo()
Dim bar As Variant
Dim foobar
bar = Array(1, 5, 10, 15, 20)

foobar = 10

Debug.Print "Value foobar", foobar, "Location " & _
Application.WorksheetFunction.Match(foobar, bar, 0)

End Sub
==============================

Note that MATCH will return a 1's based count. So if your array is 0 based,
then the "location" within the array will be offset by 1.
--ron
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
Finding the location of what was summed [email protected] Excel Worksheet Functions 3 May 21st 07 08:15 PM
Finding the location of MAX value in column milly Excel Discussion (Misc queries) 2 May 11th 07 12:15 PM
Finding Location of Maximum Value in 2D Array [email protected] Excel Discussion (Misc queries) 17 November 10th 06 02:36 PM
Finding Location of Maximum Value in 2D Array [email protected] New Users to Excel 15 November 9th 06 05:23 AM
Finding Location of Maximum Value in 2D Array [email protected] Excel Worksheet Functions 15 November 9th 06 05:23 AM


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