Using For Each to process the elements in a collection
For Each sheet in a Workbook
Code VBA add-in makes it easy to insert For Each loops. The image on the right shows it included in the Workbook menu, for all other object classes and collections similar menus exists. When selected the code block below is inserted.
Dim wb As Workbook: Set wb = ActiveWorkbook Dim ws As Worksheet For Each ws In wb.Worksheets Next ws
For Each control in an Access Form
Dim frm As Form: Set frm = Screen.ActiveForm Dim ctl As Control For Each ctl In frm.Controls Next ctl
Other pages on loops