POLYTECHNIC UNIVERSITY

CS2113 - Programming with VBA/EXCEL

Fall 2008

My lecture notes:

·         Introduction to Computers and VBA/EXCEL

 

·         More on EXCEL

 

·         Building Formulas

 

·         Using Functions

 

·         Everyday Functions

 

·         Macros

 

·         VBA in a Nutshell

 

·         VBA Essential Elements

 

Other examples covered in lecture but may not be in the above notes (they are separated loosely into categories, although many examples actually fall into multiple categories:

Branches:

·       An example involving using the Select Case statement: TestSwitch.xls

·       Computing roots of a quadratic function (involving branches): quadraticEquation0.xlsm

·       Problem 11.6: problem11p6.xls

·       Problem 11.7: problem11p7.xls

Loops:

·       An example using a nested double loop to draw the stars on the American flag: AmericanFlag.xls

·       Computing the factorial function using iteration and the use of a recursive function: TestFactorial.xls

·       Problem 12.1: problem12p1.xls

·       Problem 12.2: problem12p2.xls

·       Problem 12.3 (flow chart): flowChart12p3.xls

·       Summing the Taylor series to compute the cosine function: cosEvaluate.xls

·       Summing the Taylor series to compute the cosine function (better control of the number of terms): cosEvaluate2.xls

·       Summing the Taylor series to compute the cosine function (better control of the number of terms):cosEvaluate3.xls

·       An example using a do/while loop for data validation: doWhile.xls

Functions:

·       An example involving parameters of a function from the book: ParamList.xls

·       An example illustrating call-by-value and call-by-reference arguments of a function from the book: ValRef.xls

·       Problem 5.4: Calc5p4.xls

·       Problem 5.5: Calc5p5.xls

Arrays and Records:

·       Problem 13.3: problem13.3.xls

·       Problem 13.5 (mean and standard deviation): problem13p5.xls

·       Problem 13.11 (Equation of State):  problem13p11.xls

·       Temperature convention example from book: temperatureArray.xls

·       Finding the lowest score from an array of scores: lowestScoreArray.xls

·       Finding the differences in scores from the highest score: differenceScores.xls

·       Searching an array for a target value: Array1DSearch.xls

Miscellaneous:

·       An example of an InputBox: InputBoxTypeError.xls

·       The kickCalc example from our textbook: KickCalc.xls

·       Count number of items in spreadsheet (rows): CountRow.xls

·       Count number of items in spreadsheet (columns): CountColumn.xls

·       Problem 8.1: problem8p1.xls

·       Problem 8.3: problem8p3.xls

·       Sorting items in Excel: Sorter.xls

Midterm problems (Fall 2007): Exam questions CS2113f07e1.pdf

·       #1: e1Problem1.xls

·       #2: e1problem2.xls

·       #3: e1Problem3.xls

 

New (Fall 2008) materials:

Sub Procedures:

A simple Sub procedure involving integer arithmetic: change3.xlsm

Converting from Cartesian to polar coordinates (angles in radians and can be negative): Cartesian2PolarRadian.pdf

Computing the exponential function by summing it Taylor series: computeExp.xlsm

A Five-Cards-Game, using the VBA random number generator to generate random integers: FiveCardsGame2.xlsm

Computer simulation, to compute the area of a circle and the value of pi: MonteCarloCircle.xlsm

Using the “Preserve” keyword in a ReDim statement: Preserve.xlsm

“UBound”, “LBound” and the array size: arraySize.xlsm

A two-dimensional array: multiDimArray.xlsm

Using the function “Cells” to write to a range block on an Excel sheet: CellsExample.xlsm

Using string functions “Len”, ”InStr”, “Left”, and “Right”: testName.xlsm

Using the string function “Mid”: retrieveCharacters.xlsm

ASCII representation of characters: AscChrTest.xlsm

Read data from a range block on an Excel sheet into an array: From_sheet_make_array.xlsm

Write content from an array to a range block on an Ex

cel sheet: FillSheetArray.xlsm

Read data from a text file: InputFromFile.xlsm. An example of a text file: InputFromFile.txt

Write data to a text file: OutputToFile.xlsm

Generate a random DNA sequence: generateDNA.xlsm

Pattern matching with allowed errors: finding a given gene in a given DNA sequence: dozerDNA.xlsm

      Dozer gene sequence: dozer.dna

      DNA sequences from 4 separate students: sd1.dna, sd2.dna, sd3.dna, sd4.dna

Using VBA functions UBound, LBound to find the upper and lower bound for the index of an array, as well as the size of the array: arraySize.xlsm

Using the function Cells(i,j) to write to a range block in Excel sheet: CellsExample.xlsm

Read values from a range of cells in a spreadsheet to an array. These values are written back to the sheet at a different location, and are summed: sumArraySheet.xlsm

Read values from a range of cells in a spreadsheet to an array. The average and the standard deviation of these values are computed: standardDeviation.xlsm

Using a dynamic array to keep track of MP3 song titles: MP3Songs.xlsm

 

Exam 1 solutions:

Electrical Bill: electricityCharge.xlsm

Rolling 3 dice: threeDice9.xlsm

Computing the GCD: GCD.xlsm

 

Exam 2 solutions:

onePointCrossOver_test.xlsm

 

Exam 2: will be on 11/24 (9:00am – 10:50am)

Lecture on 11/19 will be moved to 12/8 (reading day)

 

Topics that will not be on the Final Exam: TopicsFinal.docx

 

Homework Assignments: CS2113f08Problems.htm

·       Assignment 1: problem 1

·       Assignment 2: problems 2 and 3 (due September 22 before class starts)

·       Assignment 3: problem 4 (due September 24 before class starts) change3.xlsm

·       Assignment 4: problem 5 (due October 6 before class starts) Cartesian2polar.xlsm

·       Assignment 5: problem 6 (due October 15 before class starts) CS2113f08HW05.pdf computeSine.xlsm

·       Assignment 6: problem 7 and 8 (due November 5 before class starts) CS2113f08HW06.pdf GCDSub.xlsm GCDFcn.xlsm

 

 

 

 

                  


[E-mail]| [My home page]