Professional Documents
Culture Documents
ELseIF
is a single word should not be separated
Sub Example1()
If Cells(1, 1) = 0 Then
Cells(2, 1) = "A1 is Zero"
End If
End Sub
Sub Example2()
A = 5
B = 10
If A >= B Then
Cells(1, 1) = "A is greater or equal than B"
Else
Cells(1, 1) = "B is greater than A"
End If
End Sub
Sub Example3()
For i = 1 To 10
If Reminder = 0 Then
Cells(i, 2) = "Even"
Else
Cells(i, 2) = "Odd"
End If
Next i
End Sub
Sub Example4()
For i = 1 To 10
a = Cells(i, 1)
If a > 0 Then
Cells(i, 2) = "Positive"
Cells(i, 2) = "Negative"
Else
Cells(i, 2) = "Zero"
End If
Next i
End Sub
Exercise 1: using a for loop find the count of the odd numbers in the cells
A1 to A10, place the result in cell C1
Sub Exercise1()
Count = 0
For i = 1 To 10
a = Cells(i, 1) Mod 2
If a <> 0 Then
Count = Count + 1
End If
Next i
Cells(1, 3) = Count
End Sub
Exercise 2: Find the average of the absolute values in the in the range
A1 to C5, place the result in cell B7.