Code for VBA Homeworks
|
|
- Ira Gilmore
- 6 years ago
- Views:
Transcription
1 Code for VBA Homeworks (HW1point1, HW1point2, HW2, and HW3. See vba-homeworks.xls.) vba-homework-slides.tex. For class on February 15 and 17,
2 Option Explicit Sub HW1point1() Dim AbleStartValue As Double Dim BakerStartValue As Double Dim AbleGrowthRate As Double Dim BakerGrowthRate As Double Dim AbleValue As Double Dim BakerValue As Double Dim Year As Integer Dim Done As Boolean Done = False Year = 0 2
3 AbleStartValue = Worksheets("HW1-1").Cells(2, 2).Value BakerStartValue = Worksheets("HW1-1").Cells(2, 3).Value AbleGrowthRate = Worksheets("HW1-1").Cells(3, 2).Value BakerGrowthRate = Worksheets("HW1-1").Cells(3, 3).Value AbleValue = AbleStartValue BakerValue = BakerStartValue If BakerValue >= AbleValue Then Worksheets("HW1-1").Cells(7, 1).Value = Year Worksheets("HW1-1").Cells(7, 2).Value = AbleStartValue Worksheets("HW1-1").Cells(7, 3).Value = BakerStartValue Exit Sub End If 3
4 Do While Not Done AbleValue = ValueNext(AbleValue, AbleGrowthRate) BakerValue = ValueNext(BakerValue, BakerGrowthRate) Year = Year + 1 If BakerValue >= AbleValue Then Worksheets("HW1-1").Cells(6, 1).Value = Year Worksheets("HW1-1").Cells(6, 2).Value = AbleValue Worksheets("HW1-1").Cells(6, 3).Value = BakerValue Done = True End If Loop MsgBox "Done!" End Sub 4
5 Function ValueNext(oldValue As Double, growthrate As Double) _ As Double ValueNext = oldvalue * (1 + growthrate) End Function 5
6 Option Explicit Sub HW1point2() Dim AbleStartValue As Double Dim BakerStartValue As Double Dim AbleGrowthRate As Double Dim BakerGrowthRate As Double Dim AbleValue As Double Dim BakerValue As Double Dim Year As Integer Dim Done As Boolean Dim StartYear As Integer Dim StopYear As Integer Dim mycounter As Integer 6
7 Done = False mycounter = 0 Year = 0 AbleStartValue = Worksheets("HW1-2").Cells(2, 2).Value BakerStartValue = Worksheets("HW1-2").Cells(2, 3).Value AbleGrowthRate = Worksheets("HW1-2").Cells(3, 2).Value BakerGrowthRate = Worksheets("HW1-2").Cells(3, 3).Value StartYear = Worksheets("HW1-2").Cells(4, 2).Value StopYear = Worksheets("HW1-2").Cells(5, 2).Value 7
8 ' Clear those parts of the spreadsheet as needed. ActiveSheet.Range(Cells(12, 1), Cells(12 + StopYear, 3)).Select Selection.Clear Cells(1, 1).Select 8
9 AbleValue = AbleStartValue BakerValue = BakerStartValue If BakerValue >= AbleValue Then Worksheets("HW1-2").Cells(7, 1).Value = Year Worksheets("HW1-2").Cells(7, 2).Value = AbleValue Worksheets("HW1-2").Cells(7, 3).Value = BakerValue Exit Sub End If 9
10 For Year = StartYear To StopYear AbleValue = ValueInYear(AbleStartValue, AbleGrowthRate, Year) BakerValue = ValueInYear(BakerStartValue, BakerGrowthRate, Year mycounter = mycounter + 1 Worksheets("HW1-2").Cells(11 + mycounter, 1).Value = Year Worksheets("HW1-2").Cells(11 + mycounter, 2).Value = AbleValue Worksheets("HW1-2").Cells(11 + mycounter, 3).Value = BakerValue If BakerValue >= AbleValue Then Worksheets("HW1-2").Cells(7, 1).Value = Year Worksheets("HW1-2").Cells(7, 2).Value = AbleValue Worksheets("HW1-2").Cells(7, 3).Value = BakerValue ' Put in formatting Range(Cells(12, 2), Cells(11 + mycounter, 3)).Select Selection.Style = "Currency" Cells(1, 1).Select 10
11 ' Put in termination indicators mycounter = mycounter + 1 Worksheets("HW1-2").Cells(11 + mycounter, 1).Value = "******" Worksheets("HW1-2").Cells(11 + mycounter, 2).Value = "******" Worksheets("HW1-2").Cells(11 + mycounter, 3).Value = "******" MsgBox "Found it." Exit Sub End If Next Year 11
12 Worksheets("HW1-2").Cells(7, 1).Value = "?" Worksheets("HW1-2").Cells(7, 2).Value = "?" Worksheets("HW1-2").Cells(7, 3).Value = "?" ' Put in formatting Range(Cells(12, 2), Cells(11 + mycounter, 3)).Select Selection.Style = "Currency" Cells(1, 1).Select MsgBox "Didn't find it!" End Sub 12
13 Function ValueInYear(startValue As Double, _ growthrate As Double, theyear As Integer) As Double ValueInYear = startvalue * (1 + growthrate) ^ theyear End Function 13
14 Option Explicit Sub HW2point1() Dim I As Integer Dim Vector1Length As Integer Dim Vector2Length As Integer Dim Vector1() As Double Dim Vector2() As Double Vector1Length = ActiveSheet.Range("Vector1").Rows.Count Vector2Length = ActiveSheet.Range("Vector2").Rows.Count If Vector1Length <> Vector2Length Then MsgBox "Sorry, the two vectors must have " _ & "the same length. Quitting." Exit Sub End If 14
15 ReDim Vector1(1 To Vector1Length) As Double ReDim Vector2(1 To Vector2Length) As Double For I = 1 To Vector1Length Vector1(I) = Range("Vector1").Cells(I).Value Vector2(I) = Range("Vector2").Cells(I).Value ActiveSheet.Cells(3, 4).Value = HW2DotProduct(Vector1, Vector2) End Sub Function HW2DotProduct(Vector1() As Double, _ Vector2() As Double) As Double ' Note: (Vector1, Vector2) would also work. Dim I As Integer Dim J As Integer Dim VectorLength As Integer 15
16 Dim SumSoFar As Double ' Assume that both vectors go from 1 to something. ' What's that something? I = UBound(Vector1) J = UBound(Vector2) ' Now some extra checking... If I <= J Then VectorLength = I Else VectorLength = J End If SumSoFar = 0 For I = 1 To VectorLength SumSoFar = SumSoFar + (Vector1(I) * Vector2(I)) HW2DotProduct = SumSoFar End Function 16
17 Sub HW2point2() Dim I As Integer Dim Position As Integer Dim Vector1() As Integer Dim Vector1Length As Integer Position = ActiveSheet.Range("position").Value Vector1Length = ActiveSheet.Range("ToFlip").Rows.Count ReDim Vector1(1 To Vector1Length) As Integer ' Some error checking: For I = 1 To Vector1Length Vector1(I) = Range("ToFlip").Cells(I).Value If Not (Vector1(I) = 1 Or Vector1(I) = 0) Then MsgBox "Require a 0-1 vector. Quitting." Exit Sub End If 17
18 If Position > Vector1Length Or _ Position < 1 Or Not IsNumeric(Position) Then MsgBox "Not a valid position. Quitting." Exit Sub End If Call FlipABit(Vector1, Position) For I = 1 To Vector1Length Range("Flipped").Cells(I).Value = Vector1(I) End Sub 18
19 Sub FlipABit(Vector() As Integer, Position As Integer) If Vector(Position) = 1 Then Vector(Position) = 0 Else Vector(Position) = 1 End If End Sub 19
20 Sub HW2point3() Dim Low As Integer Dim High As Integer Dim Draw As Integer Low = Range("Low").Value High = Range("High").Value ' No error checking here! Draw = LowHighRandomInt(Low, High) Range("Draw").Value = Draw End Sub Function LowHighRandomInt(L As Integer, H As Integer) As Integer LowHighRandomInt = Int(Rnd() * (H - L + 1) + L) End Function 20
21 Sub HW2point4() Dim Low As Integer Dim High As Integer Dim Rows As Integer Dim Columns As Integer Dim TheArray() As Integer Low = Range("Low").Value High = Range("High").Value Rows = Range("Rows").Value Columns = Range("Columns").Value ' No error checking here! ReDim TheArray(1 To Rows, 1 To Columns) As Integer Call ArrayRandomFill(TheArray, Low, High) Dim I As Integer Dim J As Integer 21
22 For I = 1 To UBound(TheArray, 1) For J = 1 To UBound(TheArray, 2) ActiveSheet.Cells(I + 33, J + 1).Value = TheArray(I, J) Next J End Sub Sub ArrayRandomFill(OurArray() As Integer, _ LowInt As Integer, HighInt As Integer) Dim I As Integer Dim J As Integer For I = 1 To UBound(OurArray, 1) For J = 1 To UBound(OurArray, 2) OurArray(I, J) = LowHighRandomInt(LowInt, HighInt) Next J End Sub 22
23 Sub HW2point5() Dim TwoDArray() As Integer Dim RowSums() As Integer Dim NormalizedSums() As Double Dim I As Integer Dim j As Integer ReDim TwoDArray(1 To Range("HW2point5TestArray").Rows.Count, _ 1 To Range("HW2point5TestArray").Columns.Count) As Integer ReDim RowSums(1 To UBound(TwoDArray, 1)) As Integer ReDim NormalizedSums(1 To UBound(TwoDArray, 1)) As Double 23
24 For I = 1 To UBound(TwoDArray, 1) For j = 1 To UBound(TwoDArray, 2) TwoDArray(I, j) = Range("HW2point5TestArray").Cells(I, j).value Next j ' Calculate the row sums and write them on the worksheet. Call Sum2DRows(TwoDArray, RowSums) For I = 1 To UBound(TwoDArray, 1) Range("RowSums").Cells(I).Value = RowSums(I) ' Normalize the row sums. Call NormalizeRowSums(RowSums, NormalizedSums) 24
25 Dim AZeroOneRV As Double AZeroOneRV = Rnd() Dim RowSelected As Integer Call SelectARow(NormalizedSums, AZeroOneRV, RowSelected) Range("rowpicked").Value = RowSelected End Sub 25
26 Sub Sum2DRows(AnArray() As Integer, ReturnArray() As Integer) Dim I As Integer Dim j As Integer For I = 1 To UBound(ReturnArray) ReturnArray(I) = 0 For I = 1 To UBound(AnArray, 1) For j = 1 To UBound(AnArray, 2) ReturnArray(I) = ReturnArray(I) + AnArray(I, j) Next j End Sub 26
27 Sub NormalizeRowSums(TheSums() As Integer, _ TheSumsNormalized() As Double) Dim TempSum As Double Dim I As Integer TempSum = 0 For I = 1 To UBound(TheSums) TempSum = TempSum + TheSums(I) For I = 1 To UBound(TheSums) TheSumsNormalized(I) = TheSums(I) / TempSum End Sub 27
28 Sub SelectARow(OurNormalizedSums() As Double, _ TheZeroOneRV As Double, TheRowSelected As Integer) Dim ProbSoFar As Double ProbSoFar = 0 Dim I As Integer For I = 1 To UBound(OurNormalizedSums) ProbSoFar = ProbSoFar + OurNormalizedSums(I) If TheZeroOneRV <= ProbSoFar Then TheRowSelected = I Exit Sub End If End Sub 28
29 Sub HW2point6() Dim OneDArray() As Integer Dim probmutation As Double Dim I As Integer ReDim OneDArray(1 To Range("In").Columns.Count) As Integer For I = 1 To UBound(OneDArray) OneDArray(I) = Range("In").Cells(I).Value probmutation = Range("pMutate").Value Call DoMutation(OneDArray, probmutation) For I = 1 To UBound(OneDArray) Range("Out").Cells(I).Value = OneDArray(I) End Sub 29
30 Sub DoMutation(Chromosome() As Integer, WithProb As Double) Dim I As Integer For I = 1 To UBound(Chromosome) If Rnd() <= WithProb Then Call FlipABit(Chromosome, I) End If End Sub 30
31 Sub HW2point7() Dim probcrossover As Double Dim ParentA() As Integer Dim ParentB() As Integer Dim DaughterA() As Integer Dim DaughterB() As Integer Dim I As Integer probcrossover = Range("pXOver").Value ReDim ParentA(1 To Range("ParentA").Columns.Count) ReDim ParentB(1 To Range("ParentB").Columns.Count) ReDim DaughterA(1 To Range("DaughterA").Columns.Count) ReDim DaughterB(1 To Range("DaughterB").Columns.Count) 31
32 For I = 1 To UBound(ParentA) ParentA(I) = Range("ParentA").Cells(I).Value ParentB(I) = Range("ParentB").Cells(I).Value Call DoCrossover(ParentA, ParentB, DaughterA, _ DaughterB, probcrossover) For I = 1 To UBound(ParentA) Range("DaughterA").Cells(I).Value = DaughterA(I) Range("DaughterB").Cells(I).Value = DaughterB(I) End Sub 32
33 Sub DoCrossover(FirstParent() As Integer, _ SecondParent() As Integer, FirstDaughter() As Integer, _ SecondDaughter() As Integer, xoverprob As Double) Dim xoverpoint As Integer Dim I As Integer If Rnd() > xoverprob Then ' We are not doing crossover this time. For I = 1 To UBound(FirstParent) FirstDaughter(I) = FirstParent(I) SecondDaughter(I) = SecondParent(I) Else 33
34 ' We are doing crossover this time. ' Find the point of crossingover. xoverpoint = LowHighRandomInt(1, UBound(FirstParent) - 1) For I = 1 To xoverpoint FirstDaughter(I) = FirstParent(I) SecondDaughter(I) = SecondParent(I) For I = xoverpoint + 1 To UBound(FirstParent) FirstDaughter(I) = SecondParent(I) SecondDaughter(I) = FirstParent(I) End If End Sub 34
35 HW3: IP Sensitivity Option Explicit Sub SensitivityAnalysis() Dim darownumber As Integer Dim XVector(1 To 20) As Integer Dim CVector(1 To 20) As Double Dim WVector(1 To 20) As Double Dim I As Integer Dim DotProductResult As Double Dim davariableindex As Integer Dim W As Double 35
36 Dim BestIndexSoFar As Integer Dim BestZSoFar As Double Dim AllowedSlack As Double Dim CurrentZ As Double Dim CurrentW As Double 'Get the Right-Hand-side value of the contraint W = ActiveSheet.Range("H4").Value 36
37 ' Put the row number selected ' into the column heading. darownumber = Selection.Row ActiveSheet.Range("I3").Value = darownumber davariableindex = darownumber - 3 BestIndexSoFar = davariableindex BestZSoFar = 0 AllowedSlack = ActiveSheet.Range("G2").Value ' Load the vectors For I = 1 To 20 XVector(I) = ActiveSheet.Cells(I + 3, 5).Value CVector(I) = ActiveSheet.Cells(I + 3, 3).Value WVector(I) = ActiveSheet.Cells(I + 3, 4).Value 37
38 ' Change the given XVector, flipping the ' selected position Call FlipVectorPosition(XVector, davariableindex) 38
39 ' Now find the best one-position change from here For I = 1 To 20 If I <> davariableindex Then Call FlipVectorPosition(XVector, I) CurrentZ = DotProduct(CVector, XVector) CurrentW = DotProduct(WVector, XVector) If CurrentZ > BestZSoFar And CurrentW <= W + AllowedSlack Then BestZSoFar = CurrentZ BestIndexSoFar = I End If ' Flip it back Call FlipVectorPosition(XVector, I) End If 39
40 ActiveSheet.Range("J4").Value = BestZSoFar ActiveSheet.Range("J6").Value = BestIndexSoFar Call FlipVectorPosition(XVector, BestIndexSoFar) For I = 1 To 20 ActiveSheet.Cells(I + 3, 9).Value = XVector(I) ActiveSheet.Range("J8").Value = DotProduct(WVector, XVector) End Sub 40
41 Sub FlipVectorPosition(Vector() As Integer, Position As Integer) If Vector(Position) = 1 Then Vector(Position) = 0 Else Vector(Position) = 1 End If End Sub 41
42 Function DotProduct(Vector1, Vector2) As Double Dim I As Integer Dim j As Integer Dim VectorLength As Integer Dim SumSoFar As Double ' Assume that both vectors go from 1 to something. ' What's that something? I = UBound(Vector1) j = UBound(Vector2) If I <= j Then VectorLength = I Else VectorLength = j End If 42
43 SumSoFar = 0 For I = 1 To VectorLength SumSoFar = SumSoFar + (Vector1(I) * Vector2(I)) DotProduct = SumSoFar End Function 43
IDENTIFYING UNIQUE VALUES IN AN ARRAY OR RANGE (VBA)
Date: 20/11/2012 Procedure: Identifying Unique Values In An Array Or Range (VBA) Source: LINK Permalink: LINK Created by: HeelpBook Staff Document Version: 1.0 IDENTIFYING UNIQUE VALUES IN AN ARRAY OR
More informationAgenda. Arrays 01/12/2009 INTRODUCTION TO VBA PROGRAMMING. Arrays Matrices.
INTRODUCTION TO VBA PROGRAMMING LESSON6 dario.bonino@polito.it Agenda Matrices 1 Allow to store vectorial data Geometric vectors Sets of data having something in common... Declared as Dim array_name (begin
More informationLSP 121. LSP 121 Math and Tech Literacy II. Topics. More VBA. More VBA. Variables
Greg Brewster, DePaul University Page 1 Math and Tech Literacy II Greg Brewster DePaul University Topics More Visual Basic Variables Naming Rules Implicit vs. Explicit Types Variable Lifetime Static variables
More informationAppendix A1 Visual Basics for Applications (VBA)
Credit Risk Modeling Using Excel and VBA with DVD By Gunter Löffler and Peter N. Posch 2011 John Wiley & Sons, Ltd. Appendix A1 Visual Basics for Applications (VBA) MACROS AND FUNCTIONS In this book, we
More informationDownload the files from you will use these files to finish the following exercises.
Exercise 6 Download the files from http://www.peter-lo.com/teaching/x4-xt-cdp-0071-a/source6.zip, you will use these files to finish the following exercises. 1. This exercise will guide you how to create
More informationIntroduction to VBA for Excel-Tutorial 7. The syntax to declare an array starts by using the Dim statement, such that:
Introduction to VBA for Excel-Tutorial 7 In this tutorial, you will learn deal with arrays. We will first review how to declare the arrays, then how to pass data in and how to output arrays to Excel environment.
More informationVisual Basic for Applications
Visual Basic for Applications Programming Damiano SOMENZI School of Economics and Management Advanced Computer Skills damiano.somenzi@unibz.it Week 10 Outline 1 Algorithms Sorting Exercises: exchange values,
More informationVBA Handout. References, tutorials, books. Code basics. Conditional statements. Dim myvar As <Type >
VBA Handout References, tutorials, books Excel and VBA tutorials Excel VBA Made Easy (Book) Excel 2013 Power Programming with VBA (online library reference) VBA for Modelers (Book on Amazon) Code basics
More information1. A simple solution, in which you provide a button that when clicked writes the answer to a particular cell in the worksheet.
1 H omewor k #1 V B A H o m e wo r ks 1 An investor is looking at two companies, Able and Baker. Able is a large rm, worth about $100,000,000. Baker is smaller, about $13,000,000. Both are successful and
More informationCSE 123 Introduction to Computing
CSE 123 Introduction to Computing Lecture 11 Programming with Arrays SPRING 2012 Assist. Prof. A. Evren Tugtas Array Variables Review For detailed information on array variables look at the notes of Lecture
More informationUsing Application and WorksheetFunction objects
INTRODUCTION Using Application and WorksheetFunction objects Excel provides a large number of built-in functions that can be used to perform specific calculations or to return information about your spreadsheet
More informationDATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6)
Technology & Information Management Instructor: Michael Kremer, Ph.D. Database Program: Microsoft Access Series DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6) AGENDA 3. Executing VBA
More informationControl Statements Selection (Conditional Logic)
Control Statements Selection (Conditional Logic) INTRODUCTION In the last few weeks, you were introduced to the concept of flow of control: the sequence of statements that the computer executes. In procedurally
More informationPublic Function randomdouble(lowerbound As Double, upperbound As Double) As Double On Error Resume Next
Table of Contents Introduction...1 Using VBA Functions...1 Accessing Visual Basic in Excel...2 Some Example Functions...3 Random Numbers...4 RandomDouble...4 randomint...4 Using the random numbers...5
More informationDATA 301 Introduction to Data Analytics Microsoft Excel VBA. Dr. Ramon Lawrence University of British Columbia Okanagan
DATA 301 Introduction to Data Analytics Microsoft Excel VBA Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca DATA 301: Data Analytics (2) Why Microsoft Excel Visual Basic
More informationSébastien Mathier wwwexcel-pratiquecom/en Variables : Variables make it possible to store all sorts of information Here's the first example : 'Display the value of the variable in a dialog box 'Declaring
More informationSébastien Mathier wwwexcel-pratiquecom/en Arrays are "variables" that allow many values to be stored We have already covered this topic in Lesson 3, but now we will go into greater depth Why use arrays?
More informationSub Programs. To Solve a Problem, First Make It Simpler
Sub Programs To Solve a Problem, First Make It Simpler Top Down Design Top Down Design Start with overall goal. Break Goal into Sub Goals Break Sub Goals into Sub Sub Goals Until the Sub-Sub Sub-Sub Sub-Sub
More informationENGG1811 Computing for Engineers Week 6 Iteration; Sequential Algorithms; Processing Cells
ENGG1811 Computing for Engineers Week 6 Iteration; Sequential Algorithms; Processing Cells ENGG1811 UNSW, CRICOS Provider No: 00098G1 W6 slide 1 Why loops in programming? Let us hear from Mark Zuckerberg
More informationOutline. Midterm Review. Using Excel. Midterm Review: Excel Basics. Using VBA. Sample Exam Question. Midterm Review April 4, 2014
Midterm Review Larry Caretto Mechanical Engineering 209 Computer Programming for Mechanical Engineers April 4, 2017 Outline Excel spreadsheet basics Use of VBA functions and subs Declaring/using variables
More informationCS 2113 Midterm Exam, November 6, 2007
CS 2113 Midterm Exam, November 6, 2007 Problem 1 [20 pts] When the following VBA program is executed, what will be displayed in the message box? Option Explicit Sub problem1() Dim m As Integer, n As Integer
More informationUsing loops and debugging code
Using loops and debugging code Chapter 7 Looping your code pp. 103-118 Exercises 7A & 7B Chapter 8 Fixing Bugs pp. 119-132 Exercise 8 Chapter 7 Looping your code Coding a For loop Coding a Do loop Chapter
More informationWrite the code for the click event for the Move>> button that emulates the behavior described above. Assume you already have the following code:
IS 320 Spring 2000 page 1 1. (13) The figures below show two list boxes before and after the user has clicked on the Move>> button. Notice that the selected items have been moved to the new list in the
More informationEXCEL WORKSHOP III INTRODUCTION TO MACROS AND VBA PROGRAMMING
EXCEL WORKSHOP III INTRODUCTION TO MACROS AND VBA PROGRAMMING TABLE OF CONTENTS 1. What is VBA? 2. Safety First! 1. Disabling and Enabling Macros 3. Getting started 1. Enabling the Developer tab 4. Basic
More informationVBA-Session 6. Conditional Logic. If... Then
VBA-Session 6 Conditional Logic If... Then In logic, a conditional is a statement formed by combining two sentences (or facts) using the words "if... then." It is about saying what has to happen IF a certain
More informationVBA Collections A Group of Similar Objects that Share Common Properties, Methods and
VBA AND MACROS VBA is a major division of the stand-alone Visual Basic programming language. It is integrated into Microsoft Office applications. It is the macro language of Microsoft Office Suite. Previously
More informationAPPENDIX A. This appendix contains the software code written for two programs, VictorExtract and
110 APPENDIX A This appendix contains the software code written for two programs, VictorExtract and GraphExtract for use in Microsoft Excel 2004 with Visual Basic for Applications. The former was written
More informationMonte Carlo Integration
Monte Carlo Integration The Monte Carlo method can be used to integrate a function that is difficult or impossible to evaluate by direct methods. Often the process of "integration" is the determination
More informationAgenda. Strings 30/10/2009 INTRODUCTION TO VBA PROGRAMMING. Strings Iterative constructs
INTRODUCTION TO VBA PROGRAMMING LESSON5 dario.bonino@polito.it Agenda Strings Iterative constructs For Next Do Loop Do While Loop Do Loop While Do Until Loop Do Loop Until Strings 1 Strings Variables that
More information6/14/2010. VBA program units: Subroutines and Functions. Functions: Examples: Examples:
VBA program units: Subroutines and Functions Subs: a chunk of VBA code that can be executed by running it from Excel, from the VBE, or by being called by another VBA subprogram can be created with the
More informationCS130/230 Lecture 12 Advanced Forms and Visual Basic for Applications
CS130/230 Lecture 12 Advanced Forms and Visual Basic for Applications Friday, January 23, 2004 We are going to continue using the vending machine example to illustrate some more of Access properties. Advanced
More information<excelunusual.com> Easy Zoom -Chart axis Scaling Using VBA - by George Lungu. <www.excelunusual.com> 1. Introduction: Chart naming: by George Lungu
Easy Zoom -Chart axis Scaling Using VBA - by George Lungu Introduction: - In certain models we need to be able to change the scale of the chart axes function of the result of a simulation - An Excel chart
More informationLecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan
Lecture 08-1 Programming in C++ PART 1 By Assistant Professor Dr. Ali Kattan 1 The Conditional Operator The conditional operator is similar to the if..else statement but has a shorter format. This is useful
More informationVariables in VB. Keeping Track
Variables in VB Keeping Track Variables Variables are named places in the computer memory that hold information. Variables hold only a single value at a time. Assigning a new value to them causes the old
More informationAC : SPREADSHEET TECHNIQUES FOR ENGINEERING PROFESSORS: THE CASE OF EXCEL AND ENGINEERING ECONOMICS
AC 2007-1453: SPREADSHEET TECHNIQUES FOR ENGINEERING PROFESSORS: THE CASE OF EXCEL AND ENGINEERING ECONOMICS John Ristroph, University of Louisiana-Lafayette JOHN H. RISTROPH is an emeritus Professor of
More informationIFA/QFN VBA Tutorial Notes prepared by Keith Wong
IFA/QFN VBA Tutorial Notes prepared by Keith Wong Chapter 5: Excel Object Model 5-1: Object Browser The Excel Object Model contains thousands of pre-defined classes and constants. You can view them through
More informationIn addition to the correct answer, you MUST show all your work in order to receive full credit.
In addition to the correct answer, you MUST show all your work in order to receive full credit. Questions Mark: Question1) Multiple Choice Questions /10 Question 2) Binary Trees /15 Question 3) Linked
More informationIntroduction to Arrays. Midterm Comments. Midterm Results. Midterm Comments II. Function Basics (Problem 2) Introduction to Arrays April 11, 2017
Introduction to Arrays Larry Caretto Mechanical Engineering 209 Computer Programming for Mechanical Engineers 11, 2017 Outline Review midterm Array notation and declaration Minimum subscript for arrays
More informationReview for Programming Exam and Final May 4-9, Ribbon with icons for commands Quick access toolbar (more at lecture end)
Review for Programming Exam and Final Larry Caretto Mechanical Engineering 209 Computer Programming for Mechanical Engineers May 4-9, 2017 Outline Schedule Excel Basics VBA Editor and programming variables
More informationThis project was originally conceived as a pocket database application for a mobile platform, allowing a
Dynamic Database ISYS 540 Final Project Executive Summary This project was originally conceived as a pocket database application for a mobile platform, allowing a user to dynamically build, update, and
More informationLmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions
LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions No. 9, 1st Floor, 8th Main, 9th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore 560 054 Email: itechanalytcisolutions@gmail.com Website: www.itechanalytcisolutions.com
More informationSeparate, Split & Remove Substring & Number from Text with Excel Functions & VBA
[Editor s Note: This is a guide on how to separate, split & remove substring & numbers from text using Excel Functions and VBA. Examples of substring functions are CHAR, FIND, LEFT, LOWER, MID, PROPER,
More informationMgtOp 470 Business Modeling with Spreadsheets Sample Midterm Exam. 1. Spreadsheets are known as the of business analysis.
Section 1 Multiple Choice MgtOp 470 Business Modeling with Spreadsheets Sample Midterm Exam 1. Spreadsheets are known as the of business analysis. A. German motor car B. Mexican jumping bean C. Swiss army
More informationEGR1301_Linear_Equation_Solver_ docx. 1. Select Options 2. Select Add Ins. 3. Select Solver Add in and press OK.
1. Select Options 2. Select Add Ins 3. Select Solver Add in and press OK Page 1 of 13 4. Select Analysis ToolPak and press OK 5. Select Analysis ToolPak VBA and press OK Page 2 of 13 6. From Quick Access
More informationCPSC 230 Extra review and solutions
Extra review questions: the following questions are meant to provide you with some extra practice so you need to actually try them on your own to get anything out of it. For that reason, solutions won't
More informationBASIC MACROINSTRUCTIONS (MACROS)
MS office offers a functionality of building complex actions and quasi-programs by means of a special scripting language called VBA (Visual Basic for Applications). In this lab, you will learn how to use
More informationCPSC 203 Extra review and solutions
CPSC 203 Extra review and solutions Multiple choice questions: For Questions 1 6 determine the output of the MsgBox 1) x = 12 If (x > 0) Then s = s & "a" s = s & "b" a. a b. b c. s d. ab e. None of the
More informationMicrosoft Excel 2010 Level 1
Microsoft Excel 2010 Level 1 One Day Course Course Description You have basic computer skills such as using a mouse, navigating through windows, and surfing the Internet. You have also used paper-based
More informationExcel Macro Record and VBA Editor. Presented by Wayne Wilmeth
Excel Macro Record and VBA Editor Presented by Wayne Wilmeth 1 What Is a Macro? Automates Repetitive Tasks Written in Visual Basic for Applications (VBA) Code Macro Recorder VBA Editor (Alt + F11) 2 Executing
More informationMs Excel Vba Continue Loop Through Range Of
Ms Excel Vba Continue Loop Through Range Of Rows Learn how to make your VBA code dynamic by coding in a way that allows your 5 Different Ways to Find The Last Row or Last Column Using VBA In Microsoft
More informationLearning VB.Net. Tutorial 19 Classes and Inheritance
Learning VB.Net Tutorial 19 Classes and Inheritance Hello everyone welcome to vb.net tutorials. These are going to be very basic tutorials about using the language to create simple applications, hope you
More informationLanguage Fundamentals
Language Fundamentals VBA Concepts Sept. 2013 CEE 3804 Faculty Language Fundamentals 1. Statements 2. Data Types 3. Variables and Constants 4. Functions 5. Subroutines Data Types 1. Numeric Integer Long
More informationError Vba Code For Vlookup Function In Excel 2010
Error Vba Code For Vlookup Function In Excel 2010 Users who use VLOOKUP or HLOOKUP function get N/A Error many times when In case, if there is a need to use these function in a Excel VBA Macro, then. Excel
More informationThe Tutorial Series. How to start? HP Prime Graphing Calculator. 1. Press Shift + 1 (Program). 2. Press New. It is the second touch key.
HP Prime Graphing Calculator The Tutorial Series This is the second issue of a series of tutorials for the HP Prime, written by Edward Shore. In this session, we will cover MSGBOX, IF-THEN-ELSE, PRINT,
More informationThe construction of MS Excel program:
Chapter 10 Introduction to MS Excel 2003 Introduction to Microsoft Excel 2003: MS Excel is an application program. MS Excel is the most famous spreadsheet program. We can use it mainly for calculations.
More informationCSE 123 Introduction to Computing
CSE 123 Introduction to Computing Lecture 6 Programming with VBA (Projects, forms, modules, variables, flowcharts) SPRING 2012 Assist. Prof. A. Evren Tugtas Starting with the VBA Editor Developer/Code/Visual
More informationSimply Access Tips. Issue April 26 th, Welcome to the twelfth edition of Simply Access Tips for 2007.
Hi [FirstName], Simply Access Tips Issue 12 2007 April 26 th, 2007 Welcome to the twelfth edition of Simply Access Tips for 2007. Housekeeping as usual is at the end of the Newsletter so, if you need to
More informationVisual basic tutorial problems, developed by Dr. Clement,
EXCEL Visual Basic Tutorial Problems (Version January 20, 2009) Dr. Prabhakar Clement Arthur H. Feagin Distinguished Chair Professor Department of Civil Engineering, Auburn University Home page: http://www.eng.auburn.edu/users/clemept/
More informationThe New Bisection Plus Algorithm by Namir Shammas
The New Bisection Plus Algorithm 1 The New Bisection Plus Algorithm by Namir Shammas Introduction This article presents a new variant for the root-bracketing Bisection algorithm. This new version injects
More informationMicrosoft Excel 2016 Level 1
Microsoft Excel 2016 Level 1 One Day Course Course Description You have basic computer skills such as using a mouse, navigating through windows, and surfing the Internet. You have also used paper-based
More informationHOW TO CREATE A LEGEND FOR DOOR AND WINDOW TYPES IN VECTORWORKS ARCHITECT
HOW TO CREATE A LEGEND FOR DOOR AND WINDOW TYPES IN VECTORWORKS ARCHITECT Written for Vectorworks Architect 2016 2 www.vectorworks.net DOOR AND WINDOW TYPE LEGEND With Vectorworks Design series, you are
More informationOpenOffice.org 3.2 BASIC Guide
OpenOffice.org 3.2 BASIC Guide Copyright The contents of this document are subject to the Public Documentation License. You may only use this document if you comply with the terms of the license. See:
More informationYear 8 Computing Science End of Term 3 Revision Guide
Year 8 Computing Science End of Term 3 Revision Guide Student Name: 1 Hardware: any physical component of a computer system. Input Device: a device to send instructions to be processed by the computer
More informationRevision for Final Examination (Second Semester) Grade 9
Revision for Final Examination (Second Semester) Grade 9 Name: Date: Part 1: Answer the questions given below based on your knowledge about Visual Basic 2008: Question 1 What is the benefit of using Visual
More informationd2vbaref.doc Page 1 of 22 05/11/02 14:21
Database Design 2 1. VBA or Macros?... 2 1.1 Advantages of VBA:... 2 1.2 When to use macros... 3 1.3 From here...... 3 2. A simple event procedure... 4 2.1 The code explained... 4 2.2 How does the error
More informationOBJECT ORIENTED PROGRAMMING: VBA
Agenda for Today VBA and Macro creation (using Excel) DSC340 Object-Oriented Programming Creating Macros with VBA Mike Pangburn What is O-O programming? OBJECT ORIENTED PROGRAMMING: VBA A programming style
More informationUnit 9: Excel Page( )
Unit 9: Excel Page( 496-499) Lab: A. Font B. Fill color C. Font color D. View buttons E. Numeric entry F. Row G. Cell H. Column I. Workbook window J. Active sheet K. Status bar L. Range M. Column labels
More informationwhile (condition) { body_statements; for (initialization; condition; update) { body_statements;
ITEC 136 Business Programming Concepts Week 01, Part 01 Overview 1 Week 7 Overview Week 6 review Four parts to every loop Initialization Condition Body Update Pre-test loops: condition is evaluated before
More informationENGG1811 Computing for Engineers Week 7 Iteration; Sequential Algorithms; Strings and Built-in Functions
ENGG1811 Computing for Engineers Week 7 Iteration; Sequential Algorithms; Strings and Built-in Functions ENGG1811 UNSW, CRICOS Provider No: 00098G1 W7 slide 1 References Chapra (Part 2 of ENGG1811 Text)
More informationFunction: function procedures and sub procedures share the same characteristics, with
Function: function procedures and sub procedures share the same characteristics, with one important difference- function procedures return a value (e.g., give a value back) to the caller, whereas sub procedures
More informationWelcome to 5.0 Automation Library. Using this library you can automate the features for Excel.
Introduction Welcome to the @RISK 5.0 Automation Library. Using this library you can automate the features of @RISK for Excel. Please Note: While Palisade Corporation will make every effort to maintain
More informationLertap 5 Macros for Pearson VUE Data Larry Nelson
Lertap 5 Macros for Pearson VUE Data Larry Nelson --- Lertap.com --- Document date: 24 November 2014 VUE was a company formed in 1994 as Virtual University Examinations. In 1997 NCS, National Computer
More informationA guide to writing Excel formulas and VBA macros. Mark McIlroy
A guide to writing Excel formulas and VBA macros Mark McIlroy Other books by the author The Wise Investor Introduction to the Stockmarket SQL Essentials Introduction to Computer Science Starting a Small
More informationThe For Next and For Each Loops Explained for VBA & Excel
The For Next and For Each Loops Explained for VBA & Excel excelcampus.com /vba/for-each-next-loop/ 16 Bottom line: The For Next Loops are some of the most powerful VBA macro coding techniques for automating
More informationDepiction of program declaring a variable and then assigning it a value
Programming languages I have found, the easiest first computer language to learn is VBA, the macro programming language provided with Microsoft Office. All examples below, will All modern programming languages
More informationCivil Engineering Computation
Civil Engineering Computation First Steps in VBA Homework Evaluation 2 1 Homework Evaluation 3 Based on this rubric, you may resubmit Homework 1 and Homework 2 (along with today s homework) by next Monday
More informationAgenda. First Example 24/09/2009 INTRODUCTION TO VBA PROGRAMMING. First Example. The world s simplest calculator...
INTRODUCTION TO VBA PROGRAMMING LESSON2 dario.bonino@polito.it Agenda First Example Simple Calculator First Example The world s simplest calculator... 1 Simple Calculator We want to design and implement
More informationExcel Macro Runtime Error Code 1004 Saveas Of Object _workbook Failed
Excel Macro Runtime Error Code 1004 Saveas Of Object _workbook Failed The code that follows has been courtesy of this forum and the extensive help i received from everyone. But after an Runtime Error '1004'
More informationIteration Part 1. Motivation for iteration. How does a for loop work? Execution model of a for loop. What is Iteration?
Iteration Part 1 Motivation for iteration Display time until no more time left Iteration is a problemsolving strategy found in many situations. Keep coding until all test cases passed CS111 Computer Programming
More information3/31/2016. Spreadsheets. Spreadsheets. Spreadsheets and Data Management. Unit 3. Can be used to automatically
MICROSOFT EXCEL and Data Management Unit 3 Thursday March 31, 2016 Allow users to perform simple and complex sorting Allow users to perform calculations quickly Organizes and presents figures that can
More informationIFA/QFN VBA Tutorial Notes prepared by Keith Wong
Chapter 2: Basic Visual Basic programming 2-1: What is Visual Basic IFA/QFN VBA Tutorial Notes prepared by Keith Wong BASIC is an acronym for Beginner's All-purpose Symbolic Instruction Code. It is a type
More informationLAB 5: SELECTION STATEMENTS
Statement Purpose: The purpose of this lab is to familiarize students with Conditional statements and explain how to control the sequence of statement execution, depending on the value of an expression
More informationProgramming with Microsoft Visual Basic.NET. Array. What have we learnt in last lesson? What is Array?
What have we learnt in last lesson? Programming with Microsoft Visual Basic.NET Using Toolbar in Windows Form. Using Tab Control to separate information into different tab page Storage hierarchy information
More informationModel Solutions. COMP 102: Test 1. 6 April, 2016
Family Name:.............................. Other Names:............................. ID Number:............................... Signature.................................. Model Solutions COMP 102: Test
More informationPlease answer questions in the space provided. Question point values are shown in parentheses.
IS 320 Spring 99 Page 1 Please answer questions in the space provided. Question point values are shown in parentheses. 1. (15) Assume you have the following variable declarations and assignments: Dim A
More informationFunction Exit Function End Function bold End Function Exit Function
The UDF syntax: Function name [(arguments) [As type] ] [As type] [statements] [name = expression] [Exit Function] [statements] [name = expression] - name the name of the function - arguments a list of
More informationKEYWORDS DDE GETOBJECT PATHNAME CLASS VB EDITOR WITHEVENTS HMI 1.0 TYPE LIBRARY HMI.TAG
Document Number: IX_APP00113 File Name: SpreadsheetLinking.doc Date: January 22, 2003 Product: InteractX Designer Application Note Associated Project: GetObjectDemo KEYWORDS DDE GETOBJECT PATHNAME CLASS
More informationUnit 2 Fine-tuning Spreadsheets, Functions (AutoSum)
Unit 2 Fine-tuning Spreadsheets, Functions (AutoSum) Manually adjust column width Place the pointer on the line between letters in the Column Headers. The pointer will change to double headed arrow. Hold
More informationVba Variables Constant and Data types in Excel
Vba Variables Constant and Data types in Excel VARIABLES In Excel VBA, variables are areas allocated by the computer memory to hold data. Data stored inside the computer memory has 4 properties: names,
More informationVisual Basic for Applications
Visual Basic for Applications Programming Damiano SOMENZI School of Economics and Management Advanced Computer Skills damiano.somenzi@unibz.it Week 1 Outline 1 Visual Basic for Applications Programming
More informationDroidBasic Syntax Contents
DroidBasic Syntax Contents DroidBasic Syntax...1 First Edition...3 Conventions Used In This Book / Way Of Writing...3 DroidBasic-Syntax...3 Variable...4 Declaration...4 Dim...4 Public...4 Private...4 Static...4
More informationExcel Tips and Tricks
Excel Tips and Tricks References Excel Annoyances - Curtis Frye Excel Hacks - O Reilly http://www.exceltip.com (Joseph Rubin) http://exceltips.vitalnews.com/ (Allen Wyatt) Some Excel Basics as well as
More informationAccess VBA programming
Access VBA programming TUTOR: Andy Sekiewicz MOODLE: http://moodle.city.ac.uk/ WEB: www.staff.city.ac.uk/~csathfc/acvba The DoCmd object The DoCmd object is used to code a lot of the bread and butter operations
More informationReferences. Iteration For. Iteration (Repetition) Iteration While. For loop examples
References ENGG1811 Computing for Engineers Week 7 Iteration; Sequential Algorithms; Strings and Built-in Functions Chapra (Part 2 of ENGG1811 Text) Topic 19 (chapter 12) Loops Topic 17 (section 10.1)
More informationUnit 12. Electronic Spreadsheets - Microsoft Excel. Desired Outcomes
Unit 12 Electronic Spreadsheets - Microsoft Excel Desired Outcomes Student understands Excel workbooks and worksheets Student can navigate in an Excel workbook and worksheet Student can use toolbars and
More informationVBA Excel 2013/2016. VBA Visual Basic for Applications. Learner Guide
VBA Visual Basic for Applications Learner Guide 1 Table of Contents SECTION 1 WORKING WITH MACROS...5 WORKING WITH MACROS...6 About Excel macros...6 Opening Excel (using Windows 7 or 10)...6 Recognizing
More informationBasic Programming Algorithms. 1-D Arrays
Basic Programming Algorithms 1-D Arrays 1-D fixed-size array Dim arr(5) As Double 0-base, 6 elements Dim arr(0 to 5) As Double 0-base, 6 elements Dim arr(1 to 5) As Double 1-base, 5 elements Option Base
More informationCS2630: Computer Organization Homework 1 Bits, bytes, and memory organization Due January 25, 2017, 11:59pm
CS2630: Computer Organization Homework 1 Bits, bytes, and memory organization Due January 25, 2017, 11:59pm Instructions: Show your work. Correct answers with no work will not receive full credit. Whether
More informationUnit 2 Fine-tuning Spreadsheets, Functions (AutoSum)
Unit 2 Fine-tuning Spreadsheets, Functions (AutoSum) Select a Row or a Column Place your pointer over the Column Header (gray cell at the top of a column that contains a letter identifying the column)
More informationVisual Basic for Applications
Visual Basic for Applications Programming Damiano SOMENZI School of Economics and Management Advanced Computer Skills damiano.somenzi@unibz.it Week 9 Outline 1 Logical Operators 2 Algorithms Searching
More information