| 
    
     |  | うさちゃん さん,ちくたくさん、こんばんは。 つまり、総当たりリストが作成できればよいと言うことですね?
 
 >ちょっと図にしてみました。
 >
 >下のように、A1、B1、C1のセルに、
 >例えば、1〜20まで順次入力していって、
 >E1、F1のセルに答えが返るとします。
 >これを手作業でやっていくと、
 >A1、B1、C1を変えるだけで8000回かかります。
 >この入力をVBAに任せて、出てきた答えを例えばHとIの列に、
 >上から列記されたように表示させたいのです。
 >実際にマクロを実行したら、HとIの列に8000行のデータが現れて、
 >終了するようになると思います。
 >
 >
 >A1 B1 C1 → E1 F1
 > 1 1 1 → 2 3
 > 1 1 2 → 5 7
 > 1 1 3 → 8 7
 > . . .   . .
 > . . .   . .
 > . . .   . .
 >20 20 18 → 5 0
 >20 20 19 → 9 1
 >20 20 20 → 6 4
 
 この例を引用すると
 
 標準モジュールに
 
 '=====================================================
 Sub main()
 Dim idx As Long
 Dim ans(1 To 3)
 '  ↑総当たりメンバーを取得する配列
 Dim ss As Variant
 ss = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)
 Call init_totalhit(ss, 3)
 idx = 1
 Do While get_totalhit(ans()) = 0
 Range("a1:c1").Value = ans()
 Range(Cells(idx, "h"), Cells(idx, "i")).Value = Range("e1:f1").Value
 idx = idx + 1
 Loop
 
 Call term_totalhit
 
 End Sub
 
 
 別の標準モジュールに
 '=============================================================
 Private c_myarray()
 Private c_idx() As Long
 
 '===================================================================
 Function init_totalhit(標本 As Variant, 抜取り数 As Long) As Double
 '総当たりデータをセットする
 'input : 標本 総当たりリストを作成する標本配列
 '   : 抜取り数
 'Output: init_totalhit 総あたり数
 Dim g0 As Long
 Erase c_myarray
 Erase c_idx
 ReDim c_myarray(1 To UBound(標本) - LBound(標本) + 1)
 For g0 = LBound(標本) To UBound(標本)
 c_myarray(IIf(LBound(標本) = 0, g0 + 1, g0)) = 標本(g0)
 Next g0
 init_totalhit = (UBound(標本) - LBound(標本) + 1) ^ 抜取り数
 ReDim c_idx(1 To 抜取り数)
 For idx = LBound(c_idx()) To UBound(c_idx())
 c_idx(idx) = 1
 Next
 c_idx(UBound(c_idx())) = 0
 
 End Function
 '======================================================================
 Sub term_totalhit()
 '総当たり処理の終了処理
 Erase c_myarray()
 Erase c_idx()
 End Sub
 '======================================================================
 Function get_totalhit(ans()) As Long
 '総当たりメンバーを配列に出力する
 'output: ans() メンバの配列 添え字は必ず1から始まる配列を用意する
 '    get_totalhit:0 -- 正常に配列取得
 '            1 -- メンバの終わり
 get_totalhit = 1
 For i = UBound(c_idx()) To LBound(c_idx()) Step -1
 If c_idx(i) + 1 <= UBound(c_myarray(), 1) Then
 c_idx(i) = c_idx(i) + 1
 get_totalhit = 0
 Exit For
 Else
 c_idx(i) = 1
 End If
 Next
 If get_totalhit = 0 Then
 For i = LBound(c_idx()) To UBound(c_idx())
 ans(i) = c_myarray(c_idx(i))
 Next
 End If
 End Function
 
 として、当該シートをアクティブにして
 実行してみて下さい。
 
 総当たりのリストによるセルE1、F1の結果が
 H列、i列に順次移行されます。
 
 総当たりリストは、例ではA1,B1,C1の抜取り3つですが、
 4つになっても簡単に移行出来るようにしておきました。
 試してみて下さい
 
 
 |  |