CS 106 Computing Fundamentals II Chapter 64 “For Loop Variations”

Slides:



Advertisements
Similar presentations
VBA for MS Excel Hamze Msheik. Open the Visual Basic Editor in Excel 2007 Click on the Microsoft Office button in the top left of the Excel window and.
Advertisements

VBA Modules, Functions, Variables, and Constants
PSU CS 106 Computing Fundamentals II VB Statements HM 5/19/2008.
VB .NET Programming Fundamentals
1 CS 106 Computing Fundamentals II Chapter 16 “Naming In Excel” Herbert G. Mayer, PSU CS Status 7/6/2013 Initial content copied verbatim from CS 106 material.
ECE 103 Engineering Programming Chapter 10 Variables, AKA Objects Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103.
1 CS 106 Computing Fundamentals II Chapter 17 “Introduction To VBA” Herbert G. Mayer, PSU CS status 6/30/2013 Initial content copied verbatim from CS 106.
1 CS 106 Computing Fundamentals II Chapter 25 “Variables, Assignment Statement” Herbert G. Mayer, PSU CS Status 7/4/2013 Initial content copied verbatim.
1 CS 106 Computing Fundamentals II Chapter 29 “Creating A User Form” Herbert G. Mayer, PSU CS Status 7/4/2013 Initial content copied verbatim from CS 106.
1 CS 106 Computing Fundamentals II Chapter 7 “Showing Developer Tab” Herbert G. Mayer, PSU CS status 6/17/2013 Initial content copied verbatim from CS.
1 CS 106 Computing Fundamentals II Chapter 4 “Excel Basics for Mac” Herbert G. Mayer, PSU CS status 6/27/2013 Initial content copied verbatim from CS 106.
1 CS 106 Computing Fundamentals II Chapter 34 “Conditionals In Excel” Herbert G. Mayer, PSU CS Status 7/17/2013 Initial content copied verbatim from CS.
ECE 103 Engineering Programming Chapter 61 Abstract Data Types Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material.
1 CS 106 Computing Fundamentals II Chapter 61 “Loops” Herbert G. Mayer, PSU CS Status 7/29/2013 Initial content copied verbatim from CS 106 material developed.
Week 4.  Recap – Ranges  For Each Loops  Ranges Referencing Range Objects  Set (keyword)
1 3/2/05CS250 Introduction to Computer Science II Composition and friend Functions.
1 CS 106 Computing Fundamentals II Chapter 81 “Error Handling” Herbert G. Mayer, PSU CS status 6/14/2013 Initial content copied verbatim from CS 106 material.
Lab 4 Range Review, Control Logic and Loops ► Range Review ► Control Logic and Loops ► Exercise.
ECE 103 Engineering Programming Chapter 24 Sorting Herbert G. Mayer, PSU CS Status 6/2/2015 Initial content copied verbatim from ECE 103 material developed.
1 CS 106 Computing Fundamentals II Chapter 32 “Boolean Expressions” Herbert G. Mayer, PSU CS Status 7/14/2013 Initial content copied verbatim from CS 106.
1 CS 106 Computing Fundamentals II Chapter 84 “Array Formulae” Herbert G. Mayer, PSU CS status 6/14/2013 Initial content copied verbatim from CS 106 material.
ECE 103 Engineering Programming Chapter 9 gcc Compiler Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material.
Counter-Controlled Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
1 CS 106 Computing Fundamentals II Chapter 67 “Working With Files” Herbert G. Mayer, PSU CS status 6/24/2013 Initial content copied verbatim from CS 106.
ECE 103 Engineering Programming Chapter 36 C Storage Classes Herbert G. Mayer, PSU CS Status 8/4/2014 Initial content copied verbatim from ECE 103 material.
ECE 103 Engineering Programming Chapter 55 C Math Library Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material.
1 CS 106 Computing Fundamentals II Chapter 75 “Arrays” Herbert G. Mayer, PSU CS Status 7/31/2013 Initial content copied verbatim from CS 106 material developed.
ME 142 Engineering Computation I Using Subroutines Effectively.
1 CS 106 Computing Fundamentals II Chapter 21 “Computer Organization” Herbert G. Mayer, PSU CS Status 7/9/2013 Initial content copied verbatim from CS.
1 CS 106 Computing Fundamentals II Chapter 23 “Controls And Events” Herbert G. Mayer, PSU CS Status 7/5/2013 Initial content copied verbatim from CS 106.
PSU CS 106 Computing Fundamentals II VB Declarations HM 5/4/2008.
Variables and the Assignment Statement. Basics of Variables To represent any values that a process needs to remember, we use variables Recall that variables.
ME 142 Engineering Computation I Using Subroutines Effectively.
1 CS 106 Computing Fundamentals II Chapter 211 “Coding And Debugging” Herbert G. Mayer, PSU CS status 6/29/2013 Initial content copied verbatim from CS.
1 CS 106 Computing Fundamentals II Chapter 210 “Adding Controls to User Forms” Herbert G. Mayer, PSU CS Status 7/4/2013 Initial content copied verbatim.
ECE 103 Engineering Programming Chapter 31 C Scopes Herbert G. Mayer, PSU CS Status 8/1/2015 Initial content copied verbatim from ECE 103 material developed.
1 CS 106 Computing Fundamentals II Chapter 6 “How To Zip & Unzip Files” Herbert G. Mayer, PSU CS status 6/17/2013 Initial content copied verbatim from.
ECE 103 Engineering Programming Chapter 23 Multi-Dimensional Arrays Herbert G. Mayer, PSU CS Status 6/24/2014 Initial content copied verbatim from ECE.
CS 161 Introduction to Programming and Problem Solving Chapter 17 Nested Loops Herbert G. Mayer, PSU Status 9/8/2014 Initial content copied verbatim from.
1 CS 106 Computing Fundamentals II Chapter 28 “Scope” Herbert G. Mayer, PSU CS Status 7/14/2013 Initial content copied verbatim from CS 106 material developed.
CS 161 Introduction to Programming and Problem Solving Chapter 12 C++ Statements Herbert G. Mayer, PSU Status 10/8/2014 Initial content copied verbatim.
Financial Information Management VB, VBA, VS, VSTO & VBE: Putting it all together Source: Excel VBA Programming by John Walkenbach.
1 CS 106 Computing Fundamentals II Chapter 42 “Sub Procedures And Functions” Herbert G. Mayer, PSU CS Status 8/5/2013 Initial content copied verbatim from.
Scope. Scope of Names In a small program written by one person, it is easy to be sure that each variable has a unique name In a large program, or one.
1 CS 106 Computing Fundamentals II Chapter 85 “Excel Tables” Herbert G. Mayer, PSU CS status 6/14/2013 Initial content copied verbatim from CS 106 material.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU Status 6/10/2016 Initial content copied verbatim from ECE 103 material developed.
Loops A loop is: Java provides three forms for explicit loops:
CS 106 Computing Fundamentals II Chapter 5 “Excel Basics for Windows”
CS 106 Computing Fundamentals II Chapter 35 “Controls For Choices”
CS 106 Computing Fundamentals II Chapter 77 “Algorithm”
CS 106 Computing Fundamentals II Chapter 33 “Conditional Statements”
CS 106 Computing Fundamentals II Chapter 71 “Indexing”
CS 106 Computing Fundamentals II Chapter 73 “Ranges”
CS 106 Computing Fundamentals II Chapter 66 “Working With Strings”
ECE 103 Engineering Programming Chapter 32 Array Parameters
Herbert G. Mayer, PSU CS Status 8/2/2013
ECE 103 Engineering Programming Chapter 56 Runtime Errors
ECE 103 Engineering Programming Chapter 19 Nested Loops
ECE 103 Engineering Programming Chapter 12 More C Statements
ECE 103 Engineering Programming Chapter 51 Random Numbers
ECE 103 Engineering Programming Chapter 25 C Strings, Part 1
ECE 103 Engineering Programming Chapter 46 argc, argv, envp
ECE 103 Engineering Programming Chapter 37 C Macro Parameters
ECE 103 Engineering Programming Chapter 8 Data Types and Constants
CS 106 Computing Fundamentals II Chapter 69 “Event Loop”
ECE 103 Engineering Programming Chapter 64 Tree Implementation
ECE 103 Engineering Programming Chapter 20 Change in Flow of Control
ECE 103 Engineering Programming Chapter 35 C Pointers, Part 1
Herbert G. Mayer, PSU CS Status 7/19/2015
ECE 103 Engineering Programming Chapter 18 Iteration
Presentation transcript:

CS 106 Computing Fundamentals II Chapter 64 “For Loop Variations” Herbert G. Mayer, PSU CS Status 7/20/2013 Initial content copied verbatim from CS 106 material developed by CS professors: Cynthia Brown & Robert Martin

Syllabus Different For Loop Collections Changing the Increment Make Alternate Cells Blue

Different For Loop VBA has two kinds of For loops The first kind is controlled by a variable that is automatically incremented, and runs between a beginning and ending value The second kind is a For Each loop: it is executed for every member of a collection

Collections There are various types of collections in VBA. For example, open workbooks are a collection: Sub CloseInactive() Dim Book As Workbook For Each Book In Workbooks ‘ note “In” operator! If Book.Name <> ActiveWorkBook.Name Then Book.Close End If Next Book End Sub

Changing the Increment Our examples so far have used an increment of 1 for the control variable This is the default and no special code needs to be written for it You can also use other increments, using the Step keyword to control explicit step size different from 1

Make Alternate Cells Blue Const CHANGEROW As Long = 8 Const LASTCOL As Long = 10 Sub BlueSkip() Dim j As Long For j = 1 To LASTCOL Step 2 Cells( CHANGEROW, j ).Interior.Color = vbBlue Next j ‘ but its value is: j = j + 2 End Sub