CPSC 130 Computing With Spreadsheets List Management and Macros Week 7 Outline List and Data Management Database Issues In closing … 5/29/2016 Brenda Vander Linden and Aaron Armstrong 2 List and Data Management Recall the data hierarchy: • fields • records • files Working with Excel lists (aka files) Converting data to information 5/29/2016 Brenda Vander Linden and Aaron Armstrong 3 A Data Hierarchy Bit Character, string and number Field Record File Database 5/29/2016 Brenda Vander Linden and Aaron Armstrong 4 Information from Lists Manipulating lists Filtering lists • Similar to database query features Summarizing lists with pivot tables • Similar to database report functions 5/29/2016 Brenda Vander Linden and Aaron Armstrong 5 Feature Creep Now we have facilities for sorting, input, etc., as well as a means to deal with multiple worksheets. We get something approaching a database management system (DBMS), without having a one. 5/29/2016 Brenda Vander Linden and Aaron Armstrong 6 Database Issues Database - a collection of data that is: • persistent • too large to fit into main memory Database Management System - a system that maintains and provides multi-user access to a database, and whose operation is: • efficient • convenient • safe 5/29/2016 Brenda Vander Linden and Aaron Armstrong 7 Database Issues, cont. When to use databases (and not Excel): • Large data sets • Formed input and output • Arbitrary and complicated queries • Multiple users • Security CPSC-135 covers databases 5/29/2016 Brenda Vander Linden and Aaron Armstrong 8 “All our knowledge brings us nearer to our ignorance, All our ignorance brings us nearer to death, But nearness to death, no nearer to God. Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information? The cycles of Heaven in twenty centuries Bring us farther from God and nearer to the Dust. [98] Poems 5/29/2016 T. S. Eliot, Choruses From ‘The Rock’, Selected (New York: Harcourt, Brace & World, 1964), p. 107. Brenda Vander Linden and Aaron Armstrong 9 What is a macro? • • • A set of instructions telling Excel what commands to execute Written in Visual Basic for Applications (VBA) Recorded with the Macro Recorder 5/29/2016 Brenda Vander Linden and Aaron Armstrong 10 Recording a macro • • • • NameAndCourse macro Shortcut key Record macro Stop recording 5/29/2016 Brenda Vander Linden and Aaron Armstrong 11 Elements of a Macro • • • • • Sub/End Sub Comments Variables Properties With Statement 5/29/2016 Brenda Vander Linden and Aaron Armstrong 12 Step Into • • Executes one command of the macro Other debugging commands available 5/29/2016 Brenda Vander Linden and Aaron Armstrong 13 Personal Macro workbook • • • Opened every time Excel starts Only on your machine Always accessible 5/29/2016 Brenda Vander Linden and Aaron Armstrong 14 User interaction functions • • • InputBox MsgBox Example: modifying another macro 5/29/2016 Brenda Vander Linden and Aaron Armstrong 15 The If Statement Sub Pepsi() ActiveCell = _ InputBox("Enter something interesting") If ActiveCell = "Britney" Then MsgBox ("Try Pepsi") Else MsgBox ("Try Britney") End If End Sub 5/29/2016 Brenda Vander Linden and Aaron Armstrong 16 The Do Statement Sub Redden() Range("A4").Select Do Until ActiveCell = "" Selection.Font.ColorIndex = 3 ActiveCell.Offset(1, 0).Select Loop End Sub 5/29/2016 Brenda Vander Linden and Aaron Armstrong 17