マクロ作成方法 6 (続N4ペア条件(重複無)を考える)
マクロ作成方法 5 と計算結果は同じになりますが、こちらの方法が考え方は単純に
なります。マクロは出来るだけ単純に作ったのが良いですね。
上の様にタイプ別により出目の個数をカウントして出目数関係を見るとタイプ別判別が
簡単に出来ます。判別式は4桁でも3桁(数パターン有り)でも良いですね。
出目数関係はシングル1234の場合1234がそれぞれ1つづつしかないので1111にします。
ダブル1の1123は1が4つの中で2つです。2、3は1つなので判別式2211とします。
< N4ボックスペア集計(重複なし)>
Sub n4bx_pea_tyo_non() 'ボックスペア集計 (重複なし) countifを使った例
Dim xa As long, ya As long, i As long, j As long, k As long, l As long, m As long, n As long
Dim dpt1 As long, dpt2 As long, dpt3 As long, dpt4 As long, dptn As long, deme(4) As long
Sheets("出現数").Select
Range("HB5:HK14").Select
Selection.ClearContents
i = 4
Call saikeisanoff ’再計算等止める マクロ作成方法 1 と同様
Do Until Sheets("ストレートパターン").Cells(i, 3) = ""
Cells(1, 210) = Val(Left(Sheets("ストレートパターン").Cells(i, 3), 1))
Cells(1, 211) = Val(Mid(Sheets("ストレートパターン").Cells(i, 3), 2, 1))
Cells(1, 212) = Val(Mid(Sheets("ストレートパターン").Cells(i, 3), 3, 1))
Cells(1, 213) = Val(Right(Sheets("ストレートパターン").Cells(i, 3), 1))
Cells(1, 215) = "=small(hb1:he1, 1)"
Cells(1, 216) = "=small(hb1:he1, 2)"
Cells(1, 217) = "=small(hb1:he1, 3)"
Cells(1, 218) = "=small(hb1:he1, 4)"
Cells(1, 205) = "=countif(hg1:hj1, hg1)" '千桁目の出目の数を全部計算
Cells(1, 206) = "=countif(hg1:hj1, hh1)" '百桁目の出目の数を全部計算
Cells(1, 207) = "=countif(hg1:hj1, hi1)"' ’十桁目の出目の数を全部計算
Cells(1, 208) = "=countif(hg1:hj1, hj1)"' ’一桁目の出目の数を全部計算
’各出目の数によりタイプ判別式を計算(ここでは4桁分で計算)
dptn = Cells(1, 205) & Cells(1, 206) & Cells(1, 207) & Cells(1, 208)
Cells(1, 221) = dptn ’←これは無くてもOK
For j = 1 To 4
deme(j) = Cells(1, 214 + j)
Next j
'全パターンの関係式
xa = deme(1)
ya = deme(2)
Cells(xa + 5, 210 + ya) = Cells(xa + 5, 210 + ya) + 1
Select Case dptn '各パターン判別式からの計算
Case 1111 'シングル1234 → 判別式1111
For k = 1 To 2 '出目13,14
xa = deme(1)
ya = deme(k + 2)
Cells(xa + 5, 210 + ya) = Cells(xa + 5, 210 + ya) + 1
Next k
For l = 2 To 3 '出目23,24
xa = deme(2)
ya = deme(l + 1)
Cells(xa + 5, 210 + ya) = Cells(xa + 5, 210 + ya) + 1
Next l
xa = deme(3) '出目34
ya = deme(4)
Cells(xa + 5, 210 + ya) = Cells(xa + 5, 210 + ya) + 1
Case 2211 'ダブル1123 → 判別式2211
For k = 3 To 4 '出目13,14
xa = deme(1)
ya = deme(k)
Cells(xa + 5, 210 + ya) = Cells(xa + 5, 210 + ya) + 1
Next k
xa = deme(3) '出目23
ya = deme(4)
Cells(xa + 5, 210 + ya) = Cells(xa + 5, 210 + ya) + 1
Case 1221 'ダブル1223 → 判別式1221
xa = deme(1)
ya = deme(4)
Cells(xa + 5, 210 + ya) = Cells(xa + 5, 210 + ya) + 1
For k = 3 To 4 '出目23,24
xa = deme(2)
ya = deme(k)
Cells(xa + 5, 210 + ya) = Cells(xa + 5, 210 + ya) + 1
Next k
Case 1122 'ダブル1233 → 判別式1122
xa = deme(1)
ya = deme(3)
Cells(xa + 5, 210 + ya) = Cells(xa + 5, 210 + ya) + 1
For l = 1 To 2 '出目23,34
xa = deme(l + 1)
ya = deme(l + 2)
Cells(xa + 5, 210 + ya) = Cells(xa + 5, 210 + ya) + 1
Next l
Case 2222 'ダブルダブル1122 → 判別式2222
For k = 1 To 2 '出目23 34
xa = deme(k + 1)
ya = deme(k + 2)
Cells(xa + 5, 210 + ya) = Cells(xa + 5, 210 + ya) + 1
Next k
Case 3331 'トリプル1 1112 →判別式3331
xa = deme(3)
ya = deme(4)
Cells(xa + 5, 210 + ya) = Cells(xa + 5, 210 + ya) + 1
Case 1333 'トリプル2 1222→ 判別式1333
xa = deme(3)
ya = deme(4)
Cells(xa + 5, 210 + ya) = Cells(xa + 5, 210 + ya) + 1
End Select
i = i + 1
Loop
Call saikeisanon
Cells(3, 210) = i - 4 & " 回"
Cells(1, 210).Select
End Sub
-----------------------------------------------------------------------------------------------------------
出目の数を計算するには WorksheetFunction.CountIfでも出来ますね。
Cells(1, 205) = "=countif(hg1:hj1, hg1)" '千桁目の出目の数を全部計算
Cells(1, 206) = "=countif(hg1:hj1, hh1)" '百桁目の出目の数を全部計算
Cells(1, 207) = "=countif(hg1:hj1, hi1)"' ’十桁目の出目の数を全部計算
Cells(1, 208) = "=countif(hg1:hj1, hj1)"' ’一桁目の出目の数を全部計算
↓ ↓ ↓ ↓
変数 dpt1~dpt4を使用して
dpt1 = WorksheetFunction.CountIf(Range(Cells(1, 215), Cells(1, 218)), Cells(1, 215))
dpt2 = WorksheetFunction.CountIf(Range(Cells(1, 215), Cells(1, 218)), Cells(1, 216))
dpt3 = WorksheetFunction.CountIf(Range(Cells(1, 215), Cells(1, 218)), Cells(1, 217))
dpt4 = WorksheetFunction.CountIf(Range(Cells(1, 215), Cells(1, 218)), Cells(1, 218))
判別式 を作成
dptn = dpt1 & dpt2 & dpt3 & dpt4
配列変数 dpt(4) を使用するなら For Next を使っても出来ますね。
dptn =""
For d=1 to 4
dpt(d) = WorksheetFunction.CountIf(Range(Cells(1, 215), Cells(1, 218)), Cells(1, 214+d))
dptn = dptn & dpt(d)
Next d
4444 のフォースタイプは最初に全パターンの関係式で計算しているので
Case 4444 の 条件としては いらないです。
もっと簡単に作る方法はアイデアを探す作業になります。マクロを作る前の作業として
決して易しいとは言えないです。