マクロ作成 Special Thanks to "ぱんだ氏" =================== Sub Clear() ' 以前の計算結果を消去 Worksheets("PayoffMatrix").Activate Range(Cells(4, 3), Cells(13, 12)).Value = "" Range(Cells(19, 3), Cells(28, 12)).Value = "" Range(Cells(47, 3), Cells(56, 3)).Value = "" End Sub =================== Sub Normaldistribution() ' 正規乱数の発生 Worksheets("PayoffMatrix").Activate Dim S As Integer Dim Mean As Single Dim Ver As Single Dim x As Single Dim y As Single Randomize ' S * M 行列の行数と列数の取得 ' S: 経済状態の数 ' M: 資産の数 S = Worksheets("DataSheet").Cells(7, 3) M = Worksheets("DataSheet").Cells(7, 3) ' M個の平均と分散に対して各S個ずつの正規乱数の発生 For j = 1 To M Mean = Worksheets("DataSheet").Cells(4, j + 2) Ver = Worksheets("DataSheet").Cells(5, j + 2) For i = 1 To S x = Rnd y = WorksheetFunction.NormInv(x, Mean, Ver) Worksheets("PayoffMatrix").Cells(i + 3, j + 2) = WorksheetFunction.Max(0, y) Next i Next j End Sub =================== Sub Sort() ' ソート Worksheets("PayoffMatrix").Activate Dim S As Integer S = Worksheets("DataSheet").Cells(7, 3) ' M個の各列を昇順にソート For j = 1 To S Range(Cells(4, j + 2), Cells(S + 3, j + 2)).Select Selection.Sort Key1:=Cells(3, j + 2), Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom Next j End Sub =================== Sub InverseMatrix() ' 逆行列の計算 Worksheets("PayoffMatrix").Activate Dim S As Integer S = Worksheets("DataSheet").Cells(7, 3) ' ワークシート関数を呼び出して計算 Range(Cells(19, 3), Cells(S + 18, S + 2)) = WorksheetFunction.MInverse(Range(Cells(4, 3), Cells(S + 3, S + 2))) End Sub =================== Sub MatrixMultipul() ' 行列の積を計算 Worksheets("PayoffMatrix").Activate Dim S As Integer S = Worksheets("DataSheet").Cells(7, 3) ' ワークシート関数を呼び出して計算 Range(Cells(47, 3), Cells(S + 46, 3)) = WorksheetFunction.MMult(Range(Cells(19, 3), Cells(S + 18, S + 2)), Range(Cells(33, 3), Cells(S + 32, 3))) End Sub ===================