Presentation is loading. Please wait.

Presentation is loading. Please wait.

Final Exam Review Part 4 - VBA

Similar presentations


Presentation on theme: "Final Exam Review Part 4 - VBA"— Presentation transcript:

1 Final Exam Review Part 4 - VBA
ChE 160 SI – Becca Fall 2016

2 Introduction Define/explain the following terms: MsgBox() InputBox() ‘
Option Explicit Dim ___ As ___ & ampersand .xlsm

3 Introduction- Answers
MsgBox() output/display from file InputBox() input information into VBA ‘ single apostrophe comment “ double apostrophe string Option Explicit have to dimension/define all variables as their data types Dim ___ As ___ how to dimension variables & ampersand concatenate/piece together strings and variables .xlsm how to save Macro files

4 &&& Ampersand Practice &&&

5 Common Errors Missing or misplaced “___”
Misspell MsgBox() or InputBox() Forgot to Dim variable As datatype

6 Loops Write out the basic structure of these loops If loop For loop
Do loop

7 If Loop- Answers If <conditional statement> Then
(calculations/commands) ElseIf <another conditional statement> Then (Calculations/commands) Else End If

8 For Loop- Answers For <counter> = ___ To ___ Step ____
(calculations/commands) Next <counter>

9 Do Loop- Answers Do (calculations/commands)
If <conditional statement> Then Exit Do Loop

10 Operators Define the conditional operators = <> < > <=
>=

11 Operators- Answers Conditional Operators = equal to
<> not equal to < less than > greater than <= less than or equal to >= greater than or equal to

12 Subroutines and Functions
Difference between sub routine and function Difference between ByRef and ByVal Basic structure of a function Basic structure of a subroutine

13 Subroutines- Answers Difference between sub routine and function
Sub does not return anything, function gives a final result. Also, subroutines are called Difference between ByRef and ByVal ByRef = By Reference, takes the reference variable and changes the value everywhere ByVal = By Value, only uses the values locally

14 Subroutine and Function Structure- Answers
Basic structure of a function Function <functionname> (<ByVal or ByRef> <variablename> As <data type>, …….) As <data type> (statements and calculations) <function name> = <expression> NOTE: function has function name as final variable which will be the answer displayed when run. Basic structure of a subroutine Sub <subroutinename> (<ByVal or ByRef> <variablename> As <variabletype>, ….) (statements with variables in argument list and declared in subprogram) End sub

15 Inputs and Outputs Output vs Append vs Input Print vs Write vs Input

16 Inputs and Outputs- Answers
Append Input Open (pathname\filename) For Output As #filenumber Open (pathname\filename) For Append As #filenumber Open (pathanme\filename) For Input As #filenumber VBA will create the file if one doesn't exist Has to exist before opening Write over everything in the file Adds onto a file Brings information into VBA Ends with Close #filenumber

17 Inputs and Outputs- Answers
Print Write Input Print #filenumber, [outputlist] Write #filenumber, [outputlist, comma delimited] Input #filenumber, variablelist Variables can be separated using semicolons or commas Values have to be separated by commas Values have to be designated as correct data type to be inputted ( "" around strings, everything separated by commas) Comma separates by tabs Write file has commas still in between data types Semicolon separates by spaces

18 Arrays How do you create an array using VBA?

19 Arrays- Answers For Count = 1 To 11 Column(Count, 1) = 2 * Count - 1
Next Count

20 How did that go?


Download ppt "Final Exam Review Part 4 - VBA"

Similar presentations


Ads by Google