Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
With a variable
Sub hello()
Dim username As String declare variable
username = InputBox("Please enter your name")
MsgBox "Hello " & username
End Sub
City Short
courses
Variable names
Declaring variables
Option Explicit
Sub DemoMacro()
Dim numWorkers As Integer
Dim salesRegion As String
Dim nextFinYear As Date
Dim Enrolled As Boolean
numWorkers = 571
salesRegion = "North West" If Option
nextFinYear = #4/1/2017# 'date note US format Explicit is at
Enrolled = True top of
module,
MsgBox "Number of Workers:" & numWorkers & vbNewLine _ variables
& "Sales Region: " & salesRegion & vbNewLine _ must be
& "Financial Year end: " & nextFinYear & vbNewLine _ Dimmed
& "Enrolment status: " & Enrolled
End Sub
City Short courses
City short courses
End Sub
City Short courses
Arithmetical operators
Operator Operation Example Answer
+ Add 5+4 9
- Subtract 7-2 5
* Multiply 3*5 15
/ Divide 10/4 2.5
\ N1 \ N2 - integer division 15\4 3
Mod X Mod Y returns remainder 10 mod 3 1
You are more likely to be using variables or range references than literal
numbers:
z=x+y
x=x+y
Range(C3).value = Range(D3).value Range(E3).Value
Activecell.value = activecell.offset(0,1).value /
activecell.offset(0,2).value
City Short courses
Dim x, y as Integer
Declares x as a variant, y as an integer
City Short courses
Concatenate operator
The concatenation operator is & (Shift+7). For example, you can
use it to concatenate a string to a number:
MsgBox "You will be paid " & payrate & " pounds per hour.