COMPROG MANUAL Topic5
COMPROG MANUAL Topic5
TOPIC 5
Important Tools and Excel Logic
f. If then statement
Sub MyIfstatements()
If Range (“c6”) = 12 Then
MsgBox “Good!”
End If
End Sub
g. If not equal to (<>) statement
Sub MyIfstatements()
If Range (“c6”) <> 12 Then
MsgBox “Good!”
End If
End Sub
End If
End Sub
Another Example:
Sub MyIfstatements()
If Range (“c6”) = 12 Then
MsgBox “Twelve!”
Elseif Range(“c6”) = 5 then
MsgBox “Five”
Else
MsgBox “Please enter either a Five or a Twelve”
End If
End Sub
Sub MyIfstatements()
If Range("c6") > 3 And IsNumeric(Range("c6")) Then
MsgBox "Good!"
End If
End Sub
Goto myEnding
.
.
myEnding:
EXERCISE 4
NOTE: To get the row number of the Selected cell, use Selection.Row
When user clicks on a cell and clicks blue button, the macro will use items on that row in
various columns.
Create a Macro that does the following:
1. Asks user "Add 100 to current row sales?"
2. If Yes, add 100 to Sale Amount (current row, column 4)
3. If No, do nothing
4. Assign Macro to blue button