VBAトラブル
Sub 百人一首一番から二十番()
Dim hyakuSh As Worksheet
Dim mySh As Worksheet
Set mySh = Worksheets("百人一首クイズ")
Set hyakuSh = Worksheets("百人一首")
Dim myRow As Integer
Randomize
myRow = Int((21 - 2 + 1) * Rnd + 2)
Dim kaminoku As String
Dim kaminoku2 As String
Dim kaminoku3 As String
Dim simonoku As String
Dim simonoku1 As String
Dim sakusha As String
kaminoku = hyakuSh.Cells(myRow, 3).Value
kaminoku2 = hyakuSh.Cells(myRow, 4).Value
kaminoku3 = hyakuSh.Cells(myRow, 5).Value
shimonoku = hyakuSh.Cells(myRow, 6).Value
shimonoku1 = hyakuSh.Cells(myRow, 7).Value
sakusha = hyakuSh.Cells(myRow, 8).Value
mySh.Activate
mySh.Shapes("Text Box 2").Select
Selection.Characters.Text = kaminoku & Chr(10) & kaminoku2 & Chr(10) & kaminoku3
Dim MyTBox As Integer
Dim smRow As Integer
Dim smRow2 As Integer
Dim smRow3 As Integer
Dim smRow4 As Integer
Dim smRow5 As Integer
Dim i As Integer
mySh.Shapes(2).Select
Randomize
smRow5 = Int((51 - 2 + 1) * Rnd + 2)
Selection.Characters.Text = hyakuSh.Cells(smRow5, 6).Value & Chr(10) & hyakuSh.Cells(smRow5, 7).Value & Chr(10) & hyakuSh.Cells(smRow5, 8).Value
mySh.Shapes(3).Select
Randomize
smRow = Int((51 - 2 + 1) * Rnd + 2)
Selection.Characters.Text = hyakuSh.Cells(smRow, 6).Value & Chr(10) & hyakuSh.Cells(smRow, 7).Value & Chr(10) & hyakuSh.Cells(smRow, 8).Value
mySh.Shapes(4).Select
Randomize
smRow2 = Int((51 - 2 + 1) * Rnd + 2)
Selection.Characters.Text = hyakuSh.Cells(smRow2, 6).Value & Chr(10) & hyakuSh.Cells(smRow2, 7).Value & Chr(10) & hyakuSh.Cells(smRow2, 8).Value
mySh.Shapes(5).Select
Randomize
smRow3 = Int((51 - 2 + 1) * Rnd + 2)
Selection.Characters.Text = hyakuSh.Cells(smRow3, 6).Value & Chr(10) & hyakuSh.Cells(smRow3, 7).Value & Chr(10) & hyakuSh.Cells(smRow3, 8).Value
mySh.Shapes(6).Select
Randomize
smRow4 = Int((51 - 2 + 1) * Rnd + 2)
Selection.Characters.Text = hyakuSh.Cells(smRow4, 6).Value & Chr(10) & hyakuSh.Cells(smRow4, 7).Value & Chr(10) & hyakuSh.Cells(smRow4, 8).Value
Randomize
MyTBox = Int((6 - 2 + 1) * Rnd + 2)
mySh.Shapes(MyTBox).Select
Selection.Characters.Text = shimonoku & Chr(10) & shimonoku1 & Chr(10) & sakusha
mySh.Shapes("Text Box 2").Select
Dim Ans As Integer
Ans = InputBox(hyakuSh.Cells(myRow, 3).Value & hyakuSh.Cells(myRow, 4).Value & hyakuSh.Cells(myRow, 5).Value & Chr(10) & Chr(10) & "下の句を番号で答えなさい", Title:="百人一首", Xpos:=7500, Ypos:=2500)
If Ans = MyTBox Then
MsgBox " 正解!!! V(・ o ・)V "
Else
MsgBox ("間違いです!!!!!!!!" & Chr(10) & Chr(10) & hyakuSh.Cells(myRow, 6).Value & hyakuSh.Cells(myRow, 7).Value & Chr(10) & Chr(10) & sakusha & "です")
End If
End Sub
以上のマクロをエクセルで作ったのですが、VBE~マクロを走らせると順調に走るのですが、マクロをボタンに登録すると、Inputbox に解答を掘り込んであげないと、kaminokuもshimonokuもあたらしいものになりません
今マクロはシート上にあります、マクロを標準モジュールに移しても同じ結果です。何か解決策はありますか?
かなり古くエクセル2000です、初心者なので難しいこことはわかりませんが、よろしくお願いします。
お礼
返答有難う御座います。 仰る通り、動きました!! 有難う御座いました。