Excel(エクセル) VBA入門:繰り返し処理(For〜Next,Do〜Loop) |
| スポンサードリンク | |
| For〜Next | For Each In〜Next | Do〜Loop |
| Sub rei1() Dim myCnt As Long For myCnt = 1 To 10 Cells(myCnt, 3).Value = Cells(myCnt, 1).Value * Cells(myCnt, 2).Value Next myCnt End Sub |
| Sub rei1() Dim myCnt As Long For myCnt = 1 To 10 Step 2 Cells(myCnt, 3).Value = Cells(myCnt, 1).Value * Cells(myCnt, 2).Value Next myCnt End Sub |
| Sub rei1() Dim myCnt As Long For myCnt = 1 To 10 If myCnt = 5 Then Exit For Cells(myCnt, 3).Value = Cells(myCnt, 1).Value * Cells(myCnt, 2).Value Next myCnt End Sub |
| Sub rei1() Dim myRng As Range Dim c As Range Set myRng = Range("C1:C10") For Each c In myRng c.Value = c.Offset(0, -2).Value * c.Offset(0, -1).Value Next c End Sub |
| Sub rei1() Dim myCnt As Long myCnt = 1 Do While myCnt <= 5 Cells(myCnt, 3).Value = Cells(myCnt, 1).Value * Cells(myCnt, 2).Value myCnt = myCnt + 1 Loop End Sub |
| Sub rei1() Dim myCnt As Long myCnt = 1 Do Cells(myCnt, 3).Value = Cells(myCnt, 1).Value * Cells(myCnt, 2).Value myCnt = myCnt + 1 Loop While myCnt < 6 End Sub |
| Sub rei1() Dim myCnt As Long myCnt = 1 Do Until myCnt > 5 Cells(myCnt, 3).Value = Cells(myCnt, 1).Value * Cells(myCnt, 2).Value myCnt = myCnt + 1 Loop End Sub |
| Sub rei1() Dim myCnt As Long myCnt = 1 Do Cells(myCnt, 3).Value = Cells(myCnt, 1).Value * Cells(myCnt, 2).Value myCnt = myCnt + 1 If myCnt > 5 Then Exit Do Loop End Sub |
スポンサードリンク
PageViewCounter
Since2006/2/27