CS 106 Computing Fundamentals II Chapter 73 “Ranges”

Slides:



Advertisements
Similar presentations
Two-Dimensional Arrays Chapter What is a two-dimensional array? A two-dimensional array has “rows” and “columns,” and can be thought of as a series.
Advertisements

CS 221 Chapter 2 Excel. In Excel: A1 = 95 A2 = 95 A3 = 80 A4 = 0 =IF(A1
Arrays. What is an Array? An array is a way to structure multiple pieces of data of the same type and have them readily available for multiple operations.
1 CS 106, Winter 2009 Class 19, Section 4 Slides by: Dr. Cynthia A. Brown, Instructor section 4: Dr. Herbert G. Mayer,
©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
© The McGraw-Hill Companies, 2006 Chapter 16 Two-dimensional arrays.
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.
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.
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.
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.
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.
Spreadsheet Models for Managers: Session 14 14/1 Copyright © Richard Brenner Spreadsheet Models for Managers Session 14 Using Macros II Function.
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.
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.
Variables and the Assignment Statement. Basics of Variables To represent any values that a process needs to remember, we use variables Recall that variables.
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.
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.
Ranges. Unlike many of our programming concepts, the idea of a Range is particular to Excel The ideas and code discussed in these slides can be found.
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.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
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.
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.
CS 106 Computing Fundamentals II Chapter 5 “Excel Basics for Windows”
Test 2 Review Outline.
Microsoft Visual Basic 2005: Reloaded Second Edition
Two-dimensional arrays
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”
Repeating Instructions And Advance collection
Engineering Problem Solving with C++, Etter/Ingber
CS 106 Computing Fundamentals II Chapter 71 “Indexing”
Chapter 8 Arrays Objectives
CS 106 Computing Fundamentals II Chapter 66 “Working With Strings”
CSCI N207 Data Analysis Using Spreadsheet
Multidimensional Arrays
Chapter 11 Data Structures.
Chapter 7 Part 2 Edited by JJ Shepherd
Arrays Chapter 8 Copyright © 2008 W. W. Norton & Company.
ECE 103 Engineering Programming Chapter 32 Array Parameters
Herbert G. Mayer, PSU CS Status 8/2/2013
Multidimensional array
Multidimensional Arrays
CS2011 Introduction to Programming I Multidimensional Arrays
CS 106 Computing Fundamentals II Chapter 64 “For Loop Variations”
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
INC 161 , CPE 100 Computer Programming
ECE 103 Engineering Programming Chapter 62 Stack Implementation
CS 106 Computing Fundamentals II Chapter 69 “Event Loop”
Chapter 8 Arrays Objectives
ECE 103 Engineering Programming Chapter 64 Tree Implementation
ECE 103 Engineering Programming Chapter 38 C Pointers, Part 2
Working with Arrays in MATLAB
Ps Module 7 – Part II 2D Arrays and LISTS 8/29/2019 CSE 1321 Module 7.
Introduction to Computer Science
Presentation transcript:

CS 106 Computing Fundamentals II Chapter 73 “Ranges” Herbert G. Mayer, PSU CS status 6/24/2013 Initial content copied verbatim from CS 106 material developed by CS professors: Cynthia Brown & Robert Martin

Syllabus Ranges Range is a Collection of Cells Use ForEach with Range One-Dimensional Sample Two-Dimensional Sample

Ranges Unlike many of our programming concepts, Range is particular to Excel Look for more detail in demo ForEachForNext We show how to use a For Each loop with a Range, and contrast with a For variable nested loop that will help prepare us to deal with arrays

Range is a Collection of Cells VBA in Excel has a data type Range A Range can be a single cell, a block of cells, or a group of blocks of cells (we’ll stick with the first two possibilities) You declare a Range variable in the usual way: Dim workArea As Range Dim aCell As Range

Use For Each with Range For Each loop is used when you want to do the same thing to every item in a collection A Range is a collection of cells This loop clears all cells in global range workArea: Sub ClearCells() Dim aCell As Range For Each aCell In workArea aCell.Value = Empty Next aCell End Sub

Put a 1 in Each Cell in a Range Sub ForEachDemo() Dim aCell As Range For Each aCell In workArea aCell.Value = 1 Next aCell End Sub

Treat Cells Differently If you don’t want to do the same thing with each cell, then use a different kind of loop For loops using variables work very well in this case For a range that is just a single row or column, one loop is fine For a two-dimensional range, you need nested loops

One-Dimensional Example (row) To set elements 1 to size of the first row to two times their column index: For colNdx = 1 To size Cells(1, colNdx) = 2 * colNdx Next colNdx

Two-Dimensional Example Sub ForVariableDemo() Dim rowNdx, colNdx As Long For rowNdx = 1 To size For colNdx = 1 To size Cells(rowNdx, colNdx).Value = rowNdx + colNdx Next colNdx Next rowNdx End Sub