![]() |
繰り返し処理(For〜Next,Do〜Loop):Excel VBA入門 |
スポンサードリンク | |
2022/7/22
For〜Next | For Each In〜Next | Do〜Loop |
Sub rei_1() 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 rei_1() 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 rei_1() 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 rei_1kai() Dim myCnt As Long For myCnt = 1 To 10 Cells(myCnt, 3).Value = Cells(myCnt, 1).Value * Cells(myCnt, 2).Value If Cells(myCnt, 3).Value > 150 Then Exit For Next myCnt End Sub |
Sub rei_kuku1() Dim i As Integer Dim j As Integer For i = 1 To 9 ’行番号を1〜9に変化させます For j = 1 To 9 ’列番号を1〜9に変化させます Cells(i + 1, j + 1).Value = i * j Next j Next i End Sub |
Sub rei_kuku1() Dim i As Integer Dim j As Integer For i = 1 To 9 For j = 1 To 9 Range("A1").Offset(i, j).Value = i * j Next j Next i End Sub |
Sub rei_kuku1() Dim i As Integer Dim j As Integer For i = 1 To 9 For j = 1 To 9 Range("A1").Offset(i, j).Value = _ Range("A1").Offset(i, 0).Value * Range("A1").Offset(0, j).Value Next j Next i End Sub |
Sub rei_1() 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 rei_1() 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 rei_1() 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 rei_1() 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 rei_1() 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