VBA基本 Lesson1

問題と実行結果 Lesson1

問題と実行結果 Lesson1

問題1

Sub Lesson1_1()

    Dim i As Long

    For i = 2 To 21

        Cells(i, 3).Value = Cells(i, 1).Value * 2

    Next i

End Sub

Valueを省略して Cells(i, 3) = Cells(i, 1) * 2 でも同じです

問題2

Sub Lesson1_2()

    Dim i As Long

    For i = 2 To 21

        If Cells(i, 1).Value > 50 Then

            Cells(i, 3).Value = Cells(i, 1).Value * Cells(i, 2).Value

        End If

   Next i

End Sub

問題3

Sub Lesson1_3()

    Dim i As Long, Result As Long

    For i = 2 To 21

        Result = Cells(i, 1).Value * Cells(i, 2).Value

        If Result <= 1000 Then

            Cells(i, 3).Value = Result

        End If

    Next i

End Sub

※使用している内容は、「Office TANAKA」VBA Basic セミナー受講資料から許可を得て引用しております。
田中先生ありがとうございます。