IF…THEN
Used to make decisions.
Syntax
If condition Then
statements
End If
Example
If Marks >= 40 Then
Result = “Pass”
Else
Result = “Fail”
End If
For Loop
Used to repeat actions.
Dim i As Long
For i = 2 To 10
Cells(i, 2).Value = i * 10
Next i
This writes calculated values into cells B2:B10.
For Each Loop
Useful for working with worksheet collections.
Dim ws As Worksheet
For Each ws In Worksheets
ws.Range(“A1”).Value = “Updated”
Next ws
Practice
Create a macro that checks marks from rows 2–20 and writes:
Pass or Fail
into the Result column.