Loop format | Description | Example |
For … Next | Lặp 10 lần | For i = 1 To 10 Next |
For … Next | Lặp 5 lần. i=2,4, 6 etc. | For i = 2 To 10 Step 2 Next |
For … Next | Lặp theo thứ tự ngược lại | For i = 10 To 1 Step -1 Debug.Print i Next |
For … Next | Lặp qua bộ sưu tập | For i = 1 To coll.Count Debug.Print coll(i) Next |
For … Next | Lặp qua mảng | For i = LBound(arr) To UBound(arr) Debug.Print arr(i) Next i |
For … Next | Lặp qua mảng 2D | For i = LBound(arr) To UBound(arr) For j = LBound(arr,2) To UBound(arr,2) Debug.Print arr(i, j) Next j Next i |
For Each … Next | Lặp qua bộ sưu tập | Dim item As Variant For Each item In coll Debug.Print item Next item |
For Each … Next | Lặp qua mảng | Dim item As Variant For Each item In arr Debug.Print item Next item |
For Each … Next | Lặp qua mảng 2D | Dim item As Variant For Each item In arr Debug.Print item Next item |
For Each … Next | Lặp qua dictionary | Dim key As Variant For Each key In dict.Keys Debug.Print key, dict(key) Next key |
Both types | Kết thúc vòng lặp | For i = 1 To 10 If Cells(i,1) = “found” Then Exit For End If Next i |
Đăng ký học qua Email Listen@hocexcel.online
Hộ kinh doanh Học Excel Online.
Số ĐK: 17A80048102
© Học Excel Online. All rights reserved.