How to get position of value within 2-dim array with formula?

Fractalis

Active Member
Joined
Oct 11, 2011
Messages
310
Office Version
  1. 2019
Platform
  1. Windows
Hi to all,

I have a formula that has an 1-dim array like this:

VBA Code:
{0,0,0,0,0,0,1,1,0,1,0,0,0,1,1,1}

and if I want to search "1", the result is position is 7.

VBA Code:
=MATCH(1,{0,0,0,0,0,0,1,1,0,1,0,0,0,1,1,1},0) = 7

now, if I have a 2-dim array (4x4), is there a way to look the position of first "1"?
Code:
0,0,0,0
0,0,1,1   ---> 2nd row, position 3
0,1,0,0
0,1,1,1

Is this case, the first "1" would be in position 3 of "second line". So, is the answer could be 2,3 or only 3 since I'm more interested in column position. Currently with MATCH I get #N/A

Code:
=MATCH(1,{0,0,0,0;0,0,1,1;0,1,0,0;0,1,1,1},0) =#N/A

Thanks in advance.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Are the arrays exactly as you present them or is it a range of cells?
Actually is how it looks a long formula after evaluate several steps. The final formula looks like this one with match and a 2D array.
 
Upvote 0
If you only want the column, this might work for you.
Excel Formula:
=MOD(FIND(1,TEXTJOIN("",TRUE,C7:F9)),4)
Where 4 is the number of columns and C7:F9 will be your array of 1s and 0s,
 
Upvote 0
Correction to the above should be:
Excel Formula:
=MOD(FIND(1,TEXTJOIN("",TRUE,C7:F9))-1,4)+1
Thanks so much Alex, it seems to work pretty fine.

In this case the number of columns are 4, then If I want to generalize the number of columns should be like this?

VBA Code:
=MOD(FIND(1,TEXTJOIN("",TRUE,C7:F9))-1,COLUMNS(C7:F9))+1
 
Upvote 0
Correction to the above should be:
Excel Formula:
=MOD(FIND(1,TEXTJOIN("",TRUE,C7:F9))-1,4)+1
Thanks so much Alex, it seems to work pretty fine.

In this case the number of columns are 4, then If I want to generalize the number of columns should be like this?

VBA Code:
=MOD(FIND(1,TEXTJOIN("",TRUE,C7:F9))-1,COLUMNS(C7:F9))+1
 
Upvote 0
In this case the number of columns are 4, then If I want to generalize the number of columns should be like this?
You didn't show how your array is being generated but in principle that should work.

PS: thanks for the feedback and glad we could help.
 
Upvote 1

Forum statistics

Threads
1,215,077
Messages
6,122,991
Members
449,094
Latest member
masterms

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