1

Topic: For Each for one measurement of an array

The given cycle transits on all elements of a two-dimensional array

For Each el In arr
MsgBox el
Next el

Whether it is possible to make so that For Each worked only for one measurement, for example here so:

For Each el In arr (0)
MsgBox el
Next el

2

Re: For Each for one measurement of an array

No. ForEach fulfills iteration on elements of the current container. In a two-dimensional array such element is one array cell, instead of "line" of elements.
Create not a two-dimensional array, and an array of arrays - then it will be possible.

3

Re: For Each for one measurement of an array

mr. Shu;
If write in Excel VBA it is possible to derive a line or a column from an array by means of function the INDEX. However, it has restrictions, in particular length of lines no more than 255.

For Each el In WorksheetFunction. Index (arr, 2) ' the second column under the account (not on an index)
'...
For Each el In WorksheetFunction. Index (arr, 0, 2) ' the second line under the account (not on an index)

4

Re: For Each for one measurement of an array

That is on the contrary

For Each el In WorksheetFunction. Index (arr, 2) ' the second line under the account (not on an index)
'...
For Each el In WorksheetFunction. Index (arr, 0, 2) ' the second column under the account (not on an index)

5

Re: For Each for one measurement of an array

Akina wrote:

Create not a two-dimensional array, and an array of arrays - then it will be possible.

I Range exhaust in an array, and in addition to do of it an array of arrays not so like idea, but for clarification of mechanisms of thanks!

wrote:

that is on the contrary

For Each el In WorksheetFunction. Index (arr, 2) ' the second line under the account (not on an index)
'...
For Each el In WorksheetFunction. Index (arr, 0, 2) ' the second column under the account (not on an index)

This method approached. Thanks!

6

Re: For Each for one measurement of an array

mr. Shu;
To me here it is not clear: and why nevertheless it is impossible to use For... Next? Than he was guilty? It just for such situations.

7

Re: For Each for one measurement of an array

The_Prist wrote:

mr. Shu;
To me here it is not clear: and why nevertheless it is impossible to use For... Next? Than he was guilty? It just for such situations.

He was not guilty, I and use it in the core. Simply came to mind thought to look for alternative.

8

Re: For Each for one measurement of an array

mr. Shu wrote:

came to mind thought to look for alternative.

For array ForEach - worthless alternative. It is intended for collections.