Formula to create a n x m array of sequential numbers?

MEUserII

Board Regular
Joined
Oct 27, 2017
Messages
91
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
Platform
  1. Windows
I am looking for an Excel formula to create a n (row) x m (column) array of sequential numbers; would anyone know of such a formula? As an elaboration, consider the following examples below of the desired output for different array sizes of n x m where the output array desired via formula entry is in A1. While the desired output array is entered in A1; I have showed the values visually "spilling" in to nearby cells for illustration.
For reference, I am aware that the SEQUENCE() function can do this, but I am trying to find a formula not using the SEQUENCE() function.

System Information:
OS version: Windows 10 (64-bit)
Excel Version: Excel 2016

Example Desired Formula Outputs:
n x m = 1 x 2
Formula Output in A1={1, 2}

R/C
A
B
1
1​
2​
2

n x m = 2 x 1
Formula Output in A1={1; 2}
R/C
A
B
1
1​
2
2​

n x m = 2 x 2
Formula Output in A1={1, 2; 3, 4}
R/C
A
B
1
1​
2​
2
3​
4​


n x m = 2 x 3
Formula Output in A1={1, 2, 3; 4, 5, 6}
R/C
A
B
C
1
1​
2​
3​
2
4​
5​
6​
3

n x m = 3 x 2
Formula Output in A1={1, 2; 3, 4; 5, 6}
R/C
A
B
C
1
1​
2​
2
3​
4​
3
5​
6​


n x m = 3 x 3
Formula Output in A1={1, 2, 3; 4, 5, 6; 7, 8, 9}
R/C
A
B
C
1
1​
2​
3​
2
4​
5​
6​
3
7​
8​
9​

For reference, there is a similar problem to this one of doing the reverse: taking a n x n array of values and outputting those values in to a n x 1 column; solved by Chip Pearson here: Table To Column .
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Another...

Cell Formulas
RangeFormula
D2:M11D2=IF(OR(ROWS(D$2:D2)>$A$2,COLUMNS($D2:D2)>$B$2),"",$B$2*ROWS(D$2:D2)-($B$2-1)+COLUMNS($D2:D2)-1)


Insert the formula in D2; copy down and across, say, to the range D2:M11 (gray area)

Then, try changing the values in A2 and B2 (n x m)

Hope this helps

M.
 
Upvote 0
Maybe:

Cell Formulas
RangeFormula
B2:G6B2=TRANSPOSE(ROW(INDIRECT("1:"&A3)))+(ROW(INDIRECT("1:"&A2))-1)*A3
Press CTRL+SHIFT+ENTER to enter array formulas.
@Eric W, this is very clever, ;) ; I didn't mean for the late reply as I was kept busy by some other committments.
I've rewritten your formula in to a more general version where the n x m array of sequential numbers can be represented by the respective n, m paramaters entered in to: $A$1, $B$1.

Formula entered in to $C$1: =(((ROW(INDIRECT((("$")&(1) )&(":")&(("$")&($A$1) ) ) ) )-(1) )*($A$1) )+(TRANSPOSE(ROW(INDIRECT((("$")&(1) )&(":")&(("$")&($B$1) ) ) ) ) )

Another...

Cell Formulas
RangeFormula
D2:M11D2=IF(OR(ROWS(D$2:D2)>$A$2,COLUMNS($D2:D2)>$B$2),"",$B$2*ROWS(D$2:D2)-($B$2-1)+COLUMNS($D2:D2)-1)


Insert the formula in D2; copy down and across, say, to the range D2:M11 (gray area)

Then, try changing the values in A2 and B2 (n x m)

Hope this helps

M.
@Marcelo Branco, I definitely will take a deeper look at this formula, and see how it works; and I hope to update this thread afterwards.
 
Upvote 0
I'm not sure how your version is more general, since my version also read the parameters from A2 and A3? Also, in your version, you don't really need the $ sign inside an INDIRECT, and you have a lot of unnecessary parentheses. But if you understand it, and it works for you, that's the main thing.
 
Upvote 0

Forum statistics

Threads
1,215,006
Messages
6,122,666
Members
449,091
Latest member
peppernaut

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