前の記事わかりました?以前記事に書いて載せたのか載せないのか忘れてしまって、ランダムプログラムですね。あれですよ、ほんとはロトのほうがいいのかな?無限ループ解除方法さえつかめばロトのほうは作れるんですよね、ロトの厄介なところは、同じ数字を選んではいけないんです、だから、違う数字を選ぶまでループをかけるんですよ、それで違うのを選んだら解除するようにします。ってナンバーズフォーの説明してないって、いえいえナンバーズは同数字OKですから、そんなこと関係ありません。ところが、無限ループのプログラムで止まらないってことになると、まずいかなって、ESCでとまるけどね。でもへたに妙なプログラムを使っておかしくしたらと思うとね、でもいつも話引っ張ってるとうそくさいのでのせてみました、さっきのナンバーズフォーのやり方をつかんだら、以下のプログラムを使ってみてね。(あれですよ、そのままっていうんじゃなくて、使えるところだけね、以下のプログラムは一度別のところで2通りピックアップしてそれぞれ同じ数字を選んだら、順番に選んでいって、って感じにするんですけど、別なやり方してもいいんですよ。)
Sub ExitExample()
counter = 0
myNum = 9
Do Until myNum = 10
Randomize ' 乱数発生ルーチンを初期化します。
thisrow = Range("h1").Value
myvalue1 = Int(((thisrow) * Rnd + 1))
myvalue2 = Int(((thisrow) * Rnd + 1))
myvalue3 = Int(((thisrow) * Rnd + 1))
myvalue4 = Int(((thisrow) * Rnd + 1))
myvalue5 = Int(((thisrow) * Rnd + 1))
myvalue6 = Int(((thisrow) * Rnd + 1))
myvalue7 = Int((6 * Rnd) + 1)
myvalue8 = Int((6 * Rnd) + 1)
myvalue9 = Int((6 * Rnd) + 1)
myvalue10 = Int((6 * Rnd) + 1)
myvalue11 = Int((6 * Rnd) + 1)
myvalue12 = Int((6 * Rnd) + 1)
thisrow1 = myvalue1
thisrow2 = myvalue2
thisrow3 = myvalue3
thisrow4 = myvalue4
thisrow5 = myvalue5
thisrow6 = myvalue6
thisrow7 = myvalue7
thisrow8 = myvalue8
thisrow9 = myvalue9
thisrow10 = myvalue10
thisrow11 = myvalue11
thisrow12 = myvalue12
ActiveSheet.Cells(6, 10).Value = ActiveSheet.Range(Cells(thisrow1 + 1, thisrow7), Cells(thisrow1 + 1, thisrow7)).Value
ActiveSheet.Cells(6, 11).Value = ActiveSheet.Range(Cells(thisrow2 + 1, thisrow8), Cells(thisrow2 + 1, thisrow8)).Value
ActiveSheet.Cells(6, 12).Value = ActiveSheet.Range(Cells(thisrow3 + 1, thisrow9), Cells(thisrow3 + 1, thisrow9)).Value
ActiveSheet.Cells(6, 13).Value = ActiveSheet.Range(Cells(thisrow4 + 1, thisrow10), Cells(thisrow4 + 1, thisrow10)).Value
ActiveSheet.Cells(6, 14).Value = ActiveSheet.Range(Cells(thisrow5 + 1, thisrow11), Cells(thisrow5 + 1, thisrow11)).Value
ActiveSheet.Cells(6, 15).Value = ActiveSheet.Range(Cells(thisrow6 + 1, thisrow12), Cells(thisrow6 + 1, thisrow12)).Value
myvalue13 = Int(((thisrow) * Rnd + 1))
myvalue14 = Int(((thisrow) * Rnd + 1))
myvalue15 = Int(((thisrow) * Rnd + 1))
myvalue16 = Int(((thisrow) * Rnd + 1))
myvalue17 = Int(((thisrow) * Rnd + 1))
myvalue18 = Int(((thisrow) * Rnd + 1))
myvalue19 = Int((6 * Rnd) + 1)
myvalue20 = Int((6 * Rnd) + 1)
myvalue21 = Int((6 * Rnd) + 1)
myvalue22 = Int((6 * Rnd) + 1)
myvalue23 = Int((6 * Rnd) + 1)
myvalue24 = Int((6 * Rnd) + 1)
thisrow13 = myvalue13
thisrow14 = myvalue14
thisrow15 = myvalue15
thisrow16 = myvalue16
thisrow17 = myvalue17
thisrow18 = myvalue18
thisrow19 = myvalue19
thisrow20 = myvalue20
thisrow21 = myvalue21
thisrow22 = myvalue22
thisrow23 = myvalue23
thisrow24 = myvalue24
ActiveSheet.Cells(7, 10).Value = ActiveSheet.Range(Cells(thisrow13 + 1, thisrow19), Cells(thisrow13 + 1, thisrow19)).Value
ActiveSheet.Cells(7, 11).Value = ActiveSheet.Range(Cells(thisrow14 + 1, thisrow20), Cells(thisrow14 + 1, thisrow20)).Value
ActiveSheet.Cells(7, 12).Value = ActiveSheet.Range(Cells(thisrow15 + 1, thisrow21), Cells(thisrow15 + 1, thisrow21)).Value
ActiveSheet.Cells(7, 13).Value = ActiveSheet.Range(Cells(thisrow16 + 1, thisrow22), Cells(thisrow16 + 1, thisrow22)).Value
ActiveSheet.Cells(7, 14).Value = ActiveSheet.Range(Cells(thisrow17 + 1, thisrow23), Cells(thisrow17 + 1, thisrow23)).Value
ActiveSheet.Cells(7, 15).Value = ActiveSheet.Range(Cells(thisrow18 + 1, thisrow24), Cells(thisrow18 + 1, thisrow24)).Value
If ActiveSheet.Cells(6, 10).Value = ActiveSheet.Cells(7, 10).Value And ActiveSheet.Cells(10, 10).Value = "" Then
ActiveSheet.Cells(10, 10).Value = ActiveSheet.Cells(7, 10).Value
End If
If ActiveSheet.Cells(6, 11).Value = ActiveSheet.Cells(7, 11).Value And ActiveSheet.Cells(10, 10).Value <> "" And ActiveSheet.Cells(10, 11).Value = "" And ActiveSheet.Cells(10, 10).Value <> ActiveSheet.Cells(7, 11).Value Then
ActiveSheet.Cells(10, 11).Value = ActiveSheet.Cells(7, 11).Value
End If
If ActiveSheet.Cells(6, 12).Value = ActiveSheet.Cells(7, 12).Value And ActiveSheet.Cells(10, 11).Value <> "" And ActiveSheet.Cells(10, 12).Value = "" And ActiveSheet.Cells(10, 10).Value <> ActiveSheet.Cells(7, 12).Value And ActiveSheet.Cells(10, 11).Value <> ActiveSheet.Cells(7, 12).Value Then
ActiveSheet.Cells(10, 12).Value = ActiveSheet.Cells(7, 12).Value
End If
If ActiveSheet.Cells(6, 13).Value = ActiveSheet.Cells(7, 13).Value And ActiveSheet.Cells(10, 12).Value <> "" And ActiveSheet.Cells(10, 13).Value = "" And ActiveSheet.Cells(10, 10).Value <> ActiveSheet.Cells(7, 13).Value And ActiveSheet.Cells(10, 11).Value <> ActiveSheet.Cells(7, 13).Value And ActiveSheet.Cells(10, 12).Value <> ActiveSheet.Cells(7, 13).Value Then
ActiveSheet.Cells(10, 13).Value = ActiveSheet.Cells(7, 13).Value
End If
If ActiveSheet.Cells(6, 14).Value = ActiveSheet.Cells(7, 14).Value And ActiveSheet.Cells(10, 13).Value <> "" And ActiveSheet.Cells(10, 14).Value = "" And ActiveSheet.Cells(10, 10).Value <> ActiveSheet.Cells(7, 14).Value And ActiveSheet.Cells(10, 11).Value <> ActiveSheet.Cells(7, 14).Value And ActiveSheet.Cells(10, 12).Value <> ActiveSheet.Cells(7, 14).Value And ActiveSheet.Cells(10, 13).Value <> ActiveSheet.Cells(7, 14).Value Then
ActiveSheet.Cells(10, 14).Value = ActiveSheet.Cells(7, 14).Value
End If
If ActiveSheet.Cells(6, 15).Value = ActiveSheet.Cells(7, 15).Value And ActiveSheet.Cells(10, 14).Value <> "" And ActiveSheet.Cells(10, 15).Value = "" And ActiveSheet.Cells(10, 10).Value <> ActiveSheet.Cells(7, 15).Value And ActiveSheet.Cells(10, 11).Value <> ActiveSheet.Cells(7, 15).Value And ActiveSheet.Cells(10, 12).Value <> ActiveSheet.Cells(7, 15).Value And ActiveSheet.Cells(10, 13).Value <> ActiveSheet.Cells(7, 15).Value And ActiveSheet.Cells(10, 14).Value <> ActiveSheet.Cells(7, 15).Value Then
ActiveSheet.Cells(10, 15).Value = ActiveSheet.Cells(7, 15).Value
ActiveSheet.Cells(13, 10).Value = "結果がでました!"
ActiveSheet.Cells(4, 10).Value = "リセットボタンを押してください!"
ActiveSheet.Cells(15, 10).Value = ActiveSheet.Cells(10, 10).Value
ActiveSheet.Cells(15, 11).Value = ActiveSheet.Cells(10, 11).Value
ActiveSheet.Cells(15, 12).Value = ActiveSheet.Cells(10, 12).Value
ActiveSheet.Cells(15, 13).Value = ActiveSheet.Cells(10, 13).Value
ActiveSheet.Cells(15, 14).Value = ActiveSheet.Cells(10, 14).Value
ActiveSheet.Cells(15, 15).Value = ActiveSheet.Cells(10, 15).Value
myNum = myNum + 1
End If
counter = counter + 1
If myNum > 10 Then Exit Do
Loop
MsgBox "結果は、ループ " & counter & " 回にて抽出されました。"
End Sub