Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Getting a the position of a single item in an array

Hi there

Using Excel 2003

In VBA I have a one-dimensional array of dates called dateslist() and
wish to test what position in this array a single date value (called
jdate) is at.

To do this I am using the following in my code:

datepos = Application.WorksheetFunction.Match(jdate, dateslist, 0)

BUT, it keeps returning an error "Run-time error 1004: Unable to get
the Match property of the WorksheetFunction class"

Anybody know how to fix this please? Or a better way to get the
answer I am seeking?

Many Thanks
Lloyd

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Getting a the position of a single item in an array

On 23 Jul, 17:07, pinkfloydfan wrote:
Hi there

Using Excel 2003

In VBA I have a one-dimensional array of dates called dateslist() and
wish to test what position in this array a single date value (called
jdate) is at.

To do this I am using the following in my code:

datepos = Application.WorksheetFunction.Match(jdate, dateslist, 0)

BUT, it keeps returning an error "Run-time error 1004: Unable to get
the Match property of the WorksheetFunction class"

Anybody know how to fix this please? Or a better way to get the
answer I am seeking?

Many Thanks
Lloyd


Lloyd,

The only way that I know is to loop through the array to find the
value you are looking for

e.g. where option base is 0:

For i = 0 To UBound(datelist)
If datelist(i) = jdate Then datepos = i
Next i

hth

Toyin.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Getting a the position of a single item in an array

Thanks Toyin

For the moment I have implemented a While...Wend loop and used the
value to get out the final result I need from a second array (Array2):

i = 1
While dateslist(i) < jdate
i = i + 1
Wend

if dateslist(i)<jdate then
result = 0
else
result = Array2(i)
end if

But, if anyone has a quicker way of doing it that would be great

Lloyd


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 200
Default Getting a the position of a single item in an array

If IsError(Application.Match(jdate, arr, 0)) Then
result = 0
Else
result = Application.Match(jdate, arr, 0)
End If

Alan Beban

pinkfloydfan wrote:
Thanks Toyin

For the moment I have implemented a While...Wend loop and used the
value to get out the final result I need from a second array (Array2):

i = 1
While dateslist(i) < jdate
i = i + 1
Wend

if dateslist(i)<jdate then
result = 0
else
result = Array2(i)
end if

But, if anyone has a quicker way of doing it that would be great

Lloyd




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default Getting a the position of a single item in an array

The message is telling you that there is no Match function having the
argument types associated with the data types of jdate and dateslist.

datepos = Application.WorksheetFunction.Match(jdate, dateslist, 0)


What are the data types of jdate and dateslist?

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
Return Numeric Value to their Matched Value Position in Single Column Sam via OfficeKB.com Excel Worksheet Functions 3 March 6th 07 05:18 PM
Array problem: Key words-Variant Array, single-element, type mismatch error davidm Excel Programming 6 November 9th 05 05:54 AM
Array problem: Key words-Variant Array, single-element, type mismatch error davidm Excel Programming 1 November 8th 05 04:21 AM
Mutli-dimensional Array to Single-Dimension Array Blue Aardvark Excel Programming 3 October 15th 05 09:22 AM
UDF to give position of item If list was Alpabetic cae Excel Programming 4 April 15th 04 03:00 PM


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