I posted this on the other board too.....
this may not help but it handle the matrix for n =2 to n = 5
you could mimic/extend the coding for n = 6, etc
maybe someone else knows how to handle this better
Sub macro1()
' clear old matrix
Range("A1").Select
Selection.CurrentRegion.ClearContents
'
' Read in n value
'
n = Range("nvalue").Value
i = 0
a = 1
If n = 2 Then GoTo two
If n = 3 Then GoTo three
If n = 4 Then GoTo four
If n = 5 Then GoTo five
two:
new2i:
i = i + 1
j = 0
new2j:
j = j + 1
Cells(a, 1) = i
Cells(a, 2) = j
a = a + 1
If j < 2 And j - i < 1 Then GoTo new2j Else GoTo incr2i
incr2i:
If i < 1 Then GoTo new2i Else GoTo done
three:
new3i:
i = i + 1
k = 0
j = 0
new3j:
j = j + 1
k = 0
new3k:
k = k + 1
Cells(a, 1) = i
Cells(a, 2) = j
Cells(a, 3) = k
a = a + 1
If k < 3 And k - j < 1 Then GoTo new3k Else GoTo incr3j
incr3j:
If j < 2 And j - i < 1 Then GoTo new3j Else GoTo incr3i
incr3i:
If i < 1 Then GoTo new3i Else GoTo done
four:
new4i:
i = i + 1
k = 0
j = 0
l = 0
new4j:
j = j + 1
k = 0
l = 0
new4k:
k = k + 1
l = 0
new4l:
l = l + 1
Cells(a, 1) = i
Cells(a, 2) = j
Cells(a, 3) = k
Cells(a, 4) = l
a = a + 1
If l < n And l - k < 1 Then GoTo new4l Else GoTo incr4k
incr4k:
If k < 3 And k - j < 1 Then GoTo new4k Else GoTo incr4j
incr4j:
If j < 2 And j - i < 1 Then GoTo new4j Else GoTo incr4i
incr4i:
If i < 1 Then GoTo new4i Else GoTo done
five:
new5i:
i = i + 1
k = 0
j = 0
l = 0
new5j:
j = j + 1
k = 0
l = 0
new5k:
k = k + 1
l = 0
new5l:
l = l + 1
m = 0
new5m:
m = m + 1
Cells(a, 1) = i
Cells(a, 2) = j
Cells(a, 3) = k
Cells(a, 4) = l
Cells(a, 5) = m
a = a + 1
If m < n And m - l < 1 Then GoTo new5m Else GoTo incr5l
incr5l:
If l < n And l - k < 1 Then GoTo new5l Else GoTo incr5k
incr5k:
If k < 3 And k - j < 1 Then GoTo new5k Else GoTo incr5j
incr5j:
If j < 2 And j - i < 1 Then GoTo new5j Else GoTo incr5i
incr5i:
If i < 1 Then GoTo new5i Else GoTo done
done:
End Sub
Bookmarks