How to read a given table in a specific order...

Juggler_IN

Active Member
Joined
Nov 19, 2014
Messages
349
Office Version
  1. 2003 or older
Platform
  1. Windows
There is a row by column table provided in Excel in the below format.

How to read it as A(0,0), A(1,0), A(0,1), A(2,0), A(1,1), A(0,2), A(3,0), A(2,1), A(1,2), A(0,3), ... such the output string is 1, 1, 0, 1, 1, 0, 1, 2, 2, 0, 1, 3, 6, 6, 0, 1, 4, 12, 24, 24, 0, 1, 5, 20, 60, 120, 120, 0, 1, 6, 30, 120, 360, 720, 720, 0, 1, 7, 42, 210, 840, 2520, 5040, 5040, 0, 1, 8, 56, 336, 1680, 6720, 20160, 40320, 40320, 0, ...?

n\k [0 1 2 3 4 5 6 7 8]
[0] [1, 0, 0, 0, 0, 0, 0, 0, 0]
[1] [1, 1, 2, 6, 24, 120, 720, 5040, 40320]
[2] [1, 2, 6, 24, 120, 720, 5040, 40320, 362880]
[3] [1, 3, 12, 60, 360, 2520, 20160, 181440, 1814400]
[4] [1, 4, 20, 120, 840, 6720, 60480, 604800, 6652800]
[5] [1, 5, 30, 210, 1680, 15120, 151200, 1663200, 19958400]
[6] [1, 6, 42, 336, 3024, 30240, 332640, 3991680, 51891840]
[7] [1, 7, 56, 504, 5040, 55440, 665280, 8648640, 121080960]
[8] [1, 8, 72, 720, 7920, 95040, 1235520, 17297280, 259459200]
n\k [0 1 2 3 4 5 6 7 8]
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
This will work for square matrices (i.e., row count = column count)

VBA Code:
Function SquareMatrixTo1DDiagonals(rng As Range) As Variant
    Dim r, ubrr As Long, ubrc As Long, Out, i As Long, j As Long, k As Long
    r = rng
    ubrr = UBound(r)
    ubrc = UBound(r, 2)
    ReDim Out(1 To 1, 1 To ubrr * ubrc)
    For i = 1 To ubrr
        For j = 1 To i
            k = k + 1
            Out(1, k) = r(i - j + 1, j)
        Next
    Next
    For j = 2 To ubrc
        For i = ubrr To j Step -1
            k = k + 1
            Out(1, k) = r(i, j + ubrr - i)
        Next
    Next
    SquareMatrixTo1DDiagonals = Out
End Function

Book2
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAWAXAYAZBABBBCBDBEBFBGBHBIBJBKBLBMBNBOBPBQBRBSBTBUBVBWBXBYBZCACBCC
1100000000
2112624120720504040320
312624120720504040320362880
41312603602520201601814401814400
514201208406720604806048006652800
61530210168015120151200166320019958400
71642336302430240332640399168051891840
817565045040554406652808648640121080960
91872720792095040123552017297280259459200
10
111101101220136601412242401520601201200163012036072072001742210840252050405040085633616806720201604032040320725043024151206048018144036288072050403024015120060480018144007920554403326401663200665280095040665280399168019958400123552086486405189184017297280121080960259459200
Sheet1
Cell Formulas
RangeFormula
A11:CC11A11=SquareMatrixTo1DDiagonals(A1:I9)
Dynamic array formulas.
 
Upvote 0
i used a randomarray of 10*10 as startarray, not the one you gave, but the output is the same
camspy.xlsb
ABCDEFGHIJKLMNOP
193620194435254776101-193
2422147247746397792802-142
383182864728608145591-26
4973747503030129278703-183
523152762555885646612-221
6953024737790317447501-320
71474733246416579634-197
8188751423194366763-218
938996682187997946202-347
10224460944767972278271-419
115-123
124-237
133-328
Blad2

VBA Code:
Sub SimpleLoopje()
     rijen = 10 'number of rows
     kolommen = 10 'number of columns
     rand = WorksheetFunction.RandArray(rijen, kolommen, 1, 99, 1)     '=an array of rijen*kolommmen with integers between 1 and 100
     Range("a1").Resize(rijen, kolommen).Value = rand 'write to worksheet

     For i = LBound(rand) + LBound(rand, 2) To UBound(rand) * 2
          For r = i - 1 To 1 Step -1
               k = i - r
               If WorksheetFunction.Median(LBound(rand), UBound(rand), r) = r And WorksheetFunction.Median(LBound(rand), UBound(rand), k) = k Then
                    s1 = s1 & ",'" & r & "-" & k
                    s2 = s2 & "," & rand(r, k)
                    ptr = ptr + 1
               End If
          Next
     Next
    
     Cells(1, 14).Resize(ptr) = Application.Transpose(Split(Mid(s1, 2), ","))
      Cells(1, 15).Resize(ptr) = Application.Transpose(Split(Mid(s2, 2), ","))
End Sub
 
Upvote 0
in case of an array with base 0, so 1st row=0, this small correction
VBA Code:
For r = i - 1 To lbound(and) Step -1
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,361
Members
449,080
Latest member
Armadillos

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