Loop through an entire column with Excel VBA
The code for this macro looks like this.
Sub entire_rows()
' looking for the bad donuts
bad_donuts = 0
For i = 3 To Rows.Count
donuts_quality = Cells(i, 3) ' looks at the second column
If donuts_quality = "bad" Then bad_donuts = bad_donuts + 1
Next i
' final quality statement
Range("E5").Value = "There were " & bad_donuts & " bad donuts in total"
End Sub
' looking for the bad donuts
bad_donuts = 0
For i = 3 To Rows.Count
donuts_quality = Cells(i, 3) ' looks at the second column
If donuts_quality = "bad" Then bad_donuts = bad_donuts + 1
Next i
' final quality statement
Range("E5").Value = "There were " & bad_donuts & " bad donuts in total"
End Sub