AIN3701 VBA CodingSheet 2024 1
AIN3701 VBA CodingSheet 2024 1
2024
Prepared by:
AIN3701 Lecturers
AIN3701 Coding Sheet - 2024
Dear Students
Welcome to the VBA Coding Sheet, a streamlined guide designed specifically for third-year
accounting students. This resource is crafted to support your learning journey in mastering
Visual Basic for Applications (VBA), a powerful tool used extensively in the accounting and
finance industries for automating tasks and enhancing productivity.
It is important to note that this coding sheet is not a replacement for your primary study
materials, or the invaluable experience gained from hands-on coding practice. Instead, it serves
as an additional aid, offering quick references to key concepts, syntax, and common functions.
Use it to reinforce your understanding, quickly recall essential information, and navigate
through your VBA assignments more efficiently.
Remember, true proficiency in VBA comes from a combination of thorough study and
consistent practice. Use this coding sheet to complement your learning process and to help
bridge the gap between theoretical knowledge and practical application.
Happy coding!
Kind regards
AIN3701 Lecturers
2
AIN3701 Coding Sheet - 2024
Addition imTwo = 1 + 1
Subtraction imZero = 1 – 1
Multiplication imTen = 2 * 5
3
AIN3701 Coding Sheet - 2024
Data Types
Data Type Description Bytes Example
4
AIN3701 Coding Sheet - 2024
Equals = 5=5
5
AIN3701 Coding Sheet - 2024
If Statements
Type Example scenario VBA Code
If the value stored in the variable
If val > 1000 then
“val” is greater than 1 000, print the
Simple If statement Msgbox(“Large)
text “Large”.
End If
Otherwise do nothing.
If val > 1000 then
If the value stored in the variable
Msgbox(“Large”)
“val” is greater than 1 000, print the
If-Else statement Else
text “Large”.
Msgbox(“Small”)
Otherwise, print the text “Small”.
End If
If the value stored in the variable If val > 1000 then
“val” is greater than 1 000, print the Msgbox(“Large”)
text “Large”. ElseIf val >= 200 Then
If-Elseif-Else statement If the value stored in the variable Msgbox(“Medium”)
“val” is between 200 and 1000, print Else
the text “Medium”. Msgbox(“Small”)
Otherwise, print the text “Small”. End If
6
AIN3701 Coding Sheet - 2024
Loops
Type Example scenario VBA Code
Dim Counter as Integer
For Next Loop Print the first 5 integers to the screen For Counter = 1 to 5
Msgbox(Counter)
Next Counter
Dim Counter as Integer
Counter = 1
Do While Loop Print the first 5 integers to the screen Do While Counter <= 5
Msgbox(Counter)
Counter = Counter + 1
Loop
Dim Counter as Integer
Counter = 1
Do Until Loop Print the first 5 integers to the screen Do Until Counter > 5
Msgbox(Counter)
Counter = Counter + 1
Loop
7
AIN3701 Coding Sheet - 2024
Use the Cells property to set the value of cell D3 Cells(3,4).Value = “Row 3, column 4”
Dim LastRow as Single
Select the last row where data is entered Lastrow = Cells(Rows.Count,
1).End(xlUp).Row
8
AIN3701 Coding Sheet - 2024
Add a new worksheet and specify its name Sheets.Add.Name = “My New Sheet”
9
AIN3701 Coding Sheet - 2024
10