| 
    
     |  | さらに※のようにすると、ループ回数が減ります。 
 Private Sub Worksheet_Change(ByVal Target As Range)
 'A2が変わったら実行
 If Target.Address = "$A$2" Then
 'イベントキャンセル
 Application.EnableEvents = False
 '切手組み合わせ()
 Dim I As Integer, J As Integer, K As Integer, L As Integer, M As Integer
 Dim Cpos As Long
 '
 Cpos = 3 'C列から
 For I = 0 To 4
 For J = 0 To 4 - I '←※既に選択されている分を引く
 For K = 0 To 4 - (I + J) '←※
 For L = 0 To 4 - (I + J + K) '←※
 For M = 0 To 4 - (I + J + K + L) '←※
 'ここにあったI〜Mの合計使用枚数判定は不要
 If Target.Value = 10 * I + 50 * J + 80 * K + 90 * L + 120 * M Then
 '
 Cells(3, Cpos).Value = I '10円切手枚数
 Cells(4, Cpos).Value = J '50円切手枚数
 Cells(5, Cpos).Value = K '80円切手枚数
 Cells(6, Cpos).Value = L '90円切手枚数
 Cells(7, Cpos).Value = M '120円切手枚数
 Cpos = Cpos + 1 '列番号を+1
 End If
 Next
 Next
 Next
 Next
 Next
 '戻す
 Application.EnableEvents = True
 End If
 End Sub
 
 |  |