Dim a As Long, b As Long, c As Long, e As Long, f As Long On Error Resume Next Do a = Application.InputBox("正の整数を入力してください。", , , , , , 1) If a = -1 Then Exit Sub 'ループ脱出用 -1を入力したら終了 Loop Until a > 0 Do b = Application.InputBox("正の整数を入力してください。", , , , , , 1) If b = -1 Then Exit Sub Loop Until b > 0 On Error GoTo 0 If a < b Then c = a Else c = b End If Range("A1").Value = a Range("A2").Value = b f = 1 For e = 2 To c If a Mod e = 0 Then If b Mod e = 0 Then Cells(f, "B").Value = e f = f + 1 End If End If Next