Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
y y is offline
external usenet poster
 
Posts: 60
Default extracting a subset of an array with VBA.

Hi all,

I need to extract an array from another. The dest array will contain the even element of the first one.

Which code of VBA could help me?
I've thought something this

Function Subset (source As range) As ? (I don't know, I need an array, not a range)
.... my algorithm ...
End Function

This function will be called in a cell as an argument inside several Excel functions.
Could someone tell me how can I return an array? Do I have to take care about some troubles in
particular in building this function?

Thanks in advance,
Alex.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default extracting a subset of an array with VBA.

Hi Alex,

Try this

Redim ary2(Int(Ubound(ary1,1)/2)
For i = 2 To Ubound(ary1,1) step 2
ary2(j) = ary1(i)
j=j+1
Next i

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"y" wrote in message ...
Hi all,

I need to extract an array from another. The dest array will contain the

even element of the first one.

Which code of VBA could help me?
I've thought something this

Function Subset (source As range) As ? (I don't know, I need an array, not

a range)
... my algorithm ...
End Function

This function will be called in a cell as an argument inside several Excel

functions.
Could someone tell me how can I return an array? Do I have to take care

about some troubles in
particular in building this function?

Thanks in advance,
Alex.



  #3   Report Post  
Posted to microsoft.public.excel.programming
y y is offline
external usenet poster
 
Posts: 60
Default extracting a subset of an array with VBA.

Thanks Bob,

how do I have to specify the type of function?
I never didn't need to return an array.

Perhaps this way?

Function Subset(ary1 As range) As (10,10)
Redim ary2(Int(Ubound(ary1,1)/2)
For i = 2 To Ubound(ary1,1) step 2
ary2(j) = ary1(i)
j=j+1
Next i
Subset = Ary1
End Function

I apologize if my question is trivial.

Thanks again Alex.

Bob Phillips wrote:

Hi Alex,

Try this

Redim ary2(Int(Ubound(ary1,1)/2)
For i = 2 To Ubound(ary1,1) step 2
ary2(j) = ary1(i)
j=j+1
Next i


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default extracting a subset of an array with VBA.

Not quite, like this

Function Subset(ary1 As range)
Dim ary2
Redim ary2(Int(Ubound(ary1,1)/2)
For i = 2 To Ubound(ary1,1) step 2
ary2(j) = ary1(i)
j=j+1
Next i
Subset = ary2
End Function

You don't specify the size, as it is calculated in the function itself, and
you were returning the wrong array.
--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"y" wrote in message ...
Thanks Bob,

how do I have to specify the type of function?
I never didn't need to return an array.

Perhaps this way?

Function Subset(ary1 As range) As (10,10)
Redim ary2(Int(Ubound(ary1,1)/2)
For i = 2 To Ubound(ary1,1) step 2
ary2(j) = ary1(i)
j=j+1
Next i
Subset = Ary1
End Function

I apologize if my question is trivial.

Thanks again Alex.

Bob Phillips wrote:

Hi Alex,

Try this

Redim ary2(Int(Ubound(ary1,1)/2)
For i = 2 To Ubound(ary1,1) step 2
ary2(j) = ary1(i)
j=j+1
Next i




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
Extracting a list from an array PT[_3_] Excel Worksheet Functions 1 March 1st 10 04:40 AM
Sum of a subset Gunder Excel Worksheet Functions 2 January 29th 09 01:49 PM
Sum of subset of an array Freeflyer Excel Worksheet Functions 1 June 3rd 08 05:51 PM
Populate an array that is a subset of a larger array? Jeff Excel Worksheet Functions 1 September 25th 07 12:51 AM
How to enter symbols for subset or element of a subset in Excel? rwcita Excel Worksheet Functions 1 January 23rd 06 09:27 PM


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