Inspection Details

EmptyForEachBlock


Summary
Identifies empty 'For Each...Next' blocks that can be safely removed.
Reasoning
Dead code should be removed. A loop without a body is usually redundant.
The following code example(s) would trigger this inspection:

Public Sub DoSomething()
    Dim sheet As Worksheet
    For Each sheet In ThisWorkbook.Worksheets
        ' no executable statement...
    Next
End Sub

The following code example(s) would not trigger this inspection:

Public Sub DoSomething()
    Dim sheet As Worksheet
    For Each sheet In ThisWorkbook.Worksheets
        Debug.Print sheet.Name
    Next
End Sub


Back to List