Sub foreach和in和next测试() Dim rng As Range For Each rng In Range("a1:a9") If rng = "1" Then rng.Interior.ColorIndex = 3 Else 'MsgBox rng End If Next End Sub
Sub ban() Dim i%, i1%, i2%, i3% For i = 1 To 100 Step 1 If ActiveSheet.Cells(i, 9) = "1班" Then i1 = i1 + 1 End If If ActiveSheet.Cells(i, 9) = "2班" Then i2 = i2 + 1 End If If ActiveSheet.Cells(i, 9) = "3班" Then i3 = i3 + 1 End If Next MsgBox i1 MsgBox i2 MsgBox i3 End Sub