How can I create a matrix of 300 x 300 automatically in excel

Abdmujib

Board Regular
Joined
May 15, 2022
Messages
88
Office Version
  1. 365
Platform
  1. Windows
The Picture attached is a matrix of 10 X 10 (10 columns and 10 rows). I did it manually then and it was tedious. there is now a need to do at least 300 x 300. Pls is there a way to get it done easily without doing it manually.

Thanks




Note: The earlier post got deleted and I didn't understand the reason (Was deleted reasons: pls do not bump your tread with 24hrs, as it lessen your chance of getting help).
 

Attachments

  • 1660421548252.png
    1660421548252.png
    19.8 KB · Views: 17
  • 1660421731809.png
    1660421731809.png
    23.7 KB · Views: 20
I'm not sure what you mean by function?

You could do this entirely in VBA, and dump just the results to Excel, i.e. don't use Excel formulae.

Or you could use VBA to create the Excel formulae, which is what I've done below:

Before code:
ABCD
1Lambdas
2Home Team1.1
3Away Team0.9
4
5
6
7
Sheet1

After code:
Cell Formulas
RangeFormula
C5C5=SUM($C$9:$M$19)
C9:M19C9=POISSON.DIST(C$8,$C$3,)*POISSON.DIST($B9,$C$2,)*100

VBA Code:
Sub Test()

    Dim N As Long, i As Long, hdr() As Long
   
    N = 10
    ReDim hdr(0 To N)
    For i = 0 To N
        hdr(i) = i
    Next i
   
    With Worksheets("Sheet1").Range("C9")
        .Offset(-2).Value = "Away"
        .Offset(-1).Resize(, N + 1).Value = hdr
        .Offset(-1, -1).Value = "Home"
        .Offset(, -1).Resize(N + 1).Value = Application.Transpose(hdr)
        With .Resize(N + 1, N + 1)
            .FormulaR1C1 = "=POISSON.DIST(R" & .Row - 1 & "C,R3C3,)*POISSON.DIST(RC" & .Column - 1 & ",R2C3,)*100"
            .NumberFormat = "0.00"
            .Offset(-4, -1)(1).Value = "Total"
            .Offset(-4)(1).Formula = "=SUM(" & .Address & ")"
        End With
    End With
   
End Sub

I don't, sorry. I'd have to Google it.
The bivariate poisson distribution I came across can only be use on R and I don't know how to use R
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hello Stephen, once again thanks for providing the solution to this. I want to ask a question on the next step.

Let take the matrix table as an illustration, let say I want to sum up all the home wins together on the matrix. How can I do that without suming it up manually. Is there a function that will sum up the cells in the selected range when number on the home column is greater than away row. Thanks.
 
Upvote 0
Like this perhaps:

ABCDEFGHIJKLM
1Probs
2Home win39.91%
3Draw30.64%
4Away win29.45%
5100.00%
6
7Away
8Home012345678910
9013.5312.185.481.640.370.070.010.000.000.000.00
10114.8913.406.031.810.410.070.010.000.000.000.00
1128.197.373.320.990.220.040.010.000.000.000.00
1233.002.701.220.360.080.010.000.000.000.000.00
1340.830.740.330.100.020.000.000.000.000.000.00
1450.180.160.070.020.000.000.000.000.000.000.00
1560.030.030.010.000.000.000.000.000.000.000.00
1670.010.000.000.000.000.000.000.000.000.000.00
1780.000.000.000.000.000.000.000.000.000.000.00
1890.000.000.000.000.000.000.000.000.000.000.00
19100.000.000.000.000.000.000.000.000.000.000.00
20
Sheet1
Cell Formulas
RangeFormula
C2C2=SUM((B9:B19>C8:M8)*C9:M19)/100
C3C3=SUM((B9:B19=C8:M8)*C9:M19)/100
C4C4=SUM((B9:B19<C8:M8)*C9:M19)/100
C5C5=SUM(C2:C4)
 
Upvote 0
Solution
It gave me an error (#value) when I tried it. I'm using office 16 could that be the reason?
 
Upvote 0
Thanks I figured it out. Though still not working with my excel 2016. I tried it with office 365 on my phone
 
Upvote 0

Forum statistics

Threads
1,214,629
Messages
6,120,630
Members
448,973
Latest member
ChristineC

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