Filling an paramarray

cd1001

New Member
Joined
Feb 20, 2010
Messages
13
Hello,

I wanna achieve this:

Code:
SliceArray= Worksheetfunction.Index(varArray, (Array(2, 4, 5), 0))

in a more generic style like this



Code:
Function SliceArray (p_lngStartRow as Long, p_lngEndRow as Long) as Variant

Dim varSubArr() as Variant
Dim i as Long

ReDim varSubArr(1 To (p_p_lngEndRow- p_lngStartRow) + 1)
'...
For i =Lbound(varSubArr) to Ubound(varSubArr)
varSubArr(i)= (p_lngIndexStart - 1) + i
Next i

' And then use varSubArr as Paramarray in the Worksheetfunction like this

SliceArray= Worksheetfunction.Index(varArray, 0, varSubArr))

End Function

But I get a Type-Error

How could I get this to work? Thank you very much.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
How/where exactly are you trying to use the function?

What is varArray when you get the error?

Why aren't you passing varArray to the function?

By the way, what ParamArray are you referring to?
 
Upvote 0
How/where exactly are you trying to use the function?

What is varArray when you get the error?

varArray is a public Member-Array of the class

Why aren't you passing varArray to the function?

I do, varArray is the bigger Array. From this one I try to get a smaller one (varArrSub) by using the Application.index-Function.

By the way, what ParamArray are you referring to?

Paramarray: The Index-Function can receive Array as Arguments. That means, I can get more than one Row from varArr by using the Index-Function

Thanks for reply.
 
Last edited:
Upvote 0
ParamArray (parameter array) - allows you to pass, in VBA, a variable number of arguments to a procedure.
 
Upvote 0
Ok, then we call it just array:

Look at: SliceArray= Worksheetfunction.Index(varArray, (Array(2, 4, 5), 0))
gives me a Variant-Array with three Row-Vectors (2,4,5) in it.


To clarify my Problem: I don't want to hardcode (Array(2,4,6). I wish to have a generic Array with dynamic Values and Dimensions, like this:

Worksheetfunction.Index(varArray, myArrayWithRowNumbersToSelect,0)

Any input?
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top