Chapter 13: More on Objects Spreadsheet-Based Decision Support Systems Prof. Name Position (123) 456-7890 University Name.

Slides:



Advertisements
Similar presentations
1B40: Data analysis 1 Objects Visual Basic is an (OO) object-oriented language. Performing a task in Visual Basic (VB) or.
Advertisements

Sensitivity Analysis A systematic way of asking “what-if” scenario questions in order to understand what outcomes could possibly occur that would effect.
With Microsoft ® Excel 2010© 2011 Pearson Education, Inc. Publishing as Prentice Hall1 GO! with Microsoft ® Excel 2010 Chapter 1 Creating a Worksheet and.
BCIS IB (Test 2) Excel Lessons 4 – 8 Press space bar to Advance Frame.
Introduction to Excel Formulas, Functions and References.
Visual Basic for Applications. What it does Extends the features and built in functions of Excel – Create and run VB procedures – Some may be easy to.
Lesson 14 Creating Formulas and Charting Data
Using Microsoft Office Excel 2007
With Microsoft ® Excel e © 2013 Pearson Education, Inc. Publishing as Prentice Hall1 Excel 2010 Chapter 9 Creating a Worksheet and Charting Data.
Chapter 6: Pivot Tables Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
1 Committed to Shaping the Next Generation of IT Experts. Chapter 4: Spreadsheets in Decision Making: What If? Robert Grauer and Maryann Barber Exploring.
1 CS110: Lecture 2 Spreadsheets Prepared by Fred Annexstein University of Cincinnati CC Some rights reserved Today’s Topics Basics of Excel Spreadsheets.
Sensitivity Analysis A systematic way of asking “what-if” scenario questions in order to understand what outcomes could possibly occur that would affect.
Chapter 12: Recording Macros Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Chapter 6: Pivot Tables Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Exploring Microsoft Excel 2002 Chapter 8 Chapter 8 Automating Repetitive Tasks: Macros and Visual Basic for Applications By Robert T. Grauer Maryann Barber.
Excel 2007 Part (2) Dr. Susan Al Naqshbandi
Saeed Ghanbartehrani Summer 2015 Lecture Notes #3: Manipulating Excel Objects IE 212: Computational Methods for Industrial Engineering.
Chapter 10: Working with Large Data Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Project 9 Using Visual Basic for Applications (VBA) to Customize and Automate Excel Jason C. H. Chen, Ph.D. Professor of Management Information Systems.
Spreadsheet-Based Decision Support Systems Chapter 22:
VBA for Excel. What is a spreadsheet? u An Excel spreadsheet is a set of worksheets  Each worksheets is made up of rows and columns of cells  Rows are.
Key Applications Module Lesson 16 — Excel Essentials Computer Literacy BASICS.
Chapter 11: Introduction to the Visual Basic Environment Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University.
Week 3.  Assessed Exercise 1  Working with ranges.
Chapter 17: Arrays Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Chapter 5: Charts Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Lesson 8 — Spreadsheets Unit 2 — Software. Lesson 8 – Spreadsheets 2 Objectives Understand the purpose and function of a spreadsheet. Identify the major.
1 Performing Spreadsheet What-If Analysis Applications of Spreadsheets.
Formatting Your Worksheet
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 1 Copyright © 2008 Prentice-Hall. All rights reserved. What Can I Do with a Spreadsheet.
Exploring Office 2003 Vol 1 2/e - Grauer and Barber 1 Committed to Shaping the Next Generation of IT Experts. Chapter 1 – Introduction to Excel: What is.
1 Lesson 18 Organizing and Enhancing Worksheets Computer Literacy BASICS: A Comprehensive Guide to IC 3, 3 rd Edition Morrison / Wells.
Chapter 12: Recording Macros Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Excel CREATING A WORKSHEET AND CHART. Personal Budget Worksheet We will create a personal budget worksheet that shows you income each month and your expenses.
VBA Lab 2 I ns.Samia Al-blwi. Visual Basic Grammar Object: Visual Basic is an object-oriented language. This means that all the items in Excel are thought.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Chapter 6.  If a cell style will be used over and over again it can be modified in the cell styles gallery  Home ⇒ Cell Styles ⇒ right-click a style.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. WORD 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 15 Advanced Tables.
Chapter 16: Programming Structures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Formatting WorksheetsFormatting Worksheets Lesson 7.
Chapter 16: Programming Structures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Chapter 3: Referencing and Names Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
1 Lesson 13 Organizing and Enhancing Worksheets Computer Literacy BASICS: A Comprehensive Guide to IC 3, 3 rd Edition Morrison / Wells.
Chapter 2: Excel Basics and Formatting Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Chapter 13: More on Objects Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Sensitivity Analysis A systematic way of asking “what-if” scenario questions in order to understand what outcomes could possibly occur that would affect.
Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
INTRODUCTION TO SPREADSHEETS MICROSOFT EXCEL. Spreadsheets Allows users to perform simple and complex sorting Allows users to perform calculations quickly.
Spreadsheets What is Excel?. Objectives 1. Identify the parts of the Excel Screen 2. Identify the functions of a spreadsheet 3. Identify how spreadsheets.
Sensitivity Analysis A systematic way of asking “what-if” scenario questions in order to understand what outcomes could possibly occur that would effect.
Chapter 3: Referencing and Names Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Chapter 2: Excel Basics and Formatting Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Chapter 15: Sub Procedures and Function Procedures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University.
Microsoft Excel 2007 Noris Bt. Ismail Faculty of Information and Communication Technology Tel : (Ext 8408) BCOMP0101.
COMPUTER LITERACY NOTES MS-EXCEL. SPREADSHEETS A spreadsheet is a computer equivalent of a paper ledger sheet. Excel allows you to create spreadsheets.
April 9 th, Saturday PDP N° Malik Koné. I. Cells A. The Concept B. Properties, Types and Formats II. Spreadsheets A. Spreadsheet’s Elements B. Selection.
Chapter 5: Charts & Sparklines Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Exploring Office Grauer and Barber 1 Committed to Shaping the Next Generation of IT Experts. Chapter 1 – Introduction to Excel: What is a Spreadsheet?
Chapter 6 Modifying Cell Styles
Microsoft Excel.
Formatting a Worksheet
Spreadsheet-Based Decision Support Systems
Exploring Microsoft Excel
Objectives At the end of this session, students will be able to:
Intro to Excel CSCI-150.
GO! with Microsoft® Excel 2010
Activate a range and manipulating activated range
Key Applications Module Lesson 16 — Excel Essentials
Chapter 6 Modifying Cell Styles
Presentation transcript:

Chapter 13: More on Objects Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name

2 Overview  13.1 Introduction  13.2 More on Properties and Methods  13.3 The With Construct  13.4 Referencing in VBA  13.5 Formulas in VBA  13.6 Summary

3 Introduction  Various properties and methods for commonly manipulated objects.  The With construct.  Cell referencing and naming in VBA.  Excel formulas and functions in VBA.

4 More on Properties and Methods  Workbooks and worksheets  Ranges  Charts  Drawing objects  Application

5 Workbooks and Worksheets  Workbooks and Worksheets will not be manipulated too often.  There is one important method that both use –Activate; argument = (none)  There is one important property that Worksheets often use –Visible; value = True or False

6 Figures 13.1 and 13.2  For example, we want to take some values from a workbook called “CH13 Workbook1” and transfer them into a chart or another form of analysis in a different workbook, “CH13 Workbook2.”

7 Figure 13.3  Before copying the data, we need to specify which workbook is active.  To make a workbook active, we use the Activate method.  We can find Activate in the drop-down list of methods and properties for the workbook object.

8 Figure 13.4  We copy the required cells of data for the first chart; and paste this data into “CH13 Workbook2”.  We use the Range object and the PasteSpecial method. This method takes one argument which specifies how the data should be pasted.  We use the argument xlPasteAll to paste the data as is.

9 Figure 13.5  The code copies two different sets of data from one workbook to another.

10 Workbooks and Worksheets (cont’d)  We commonly make Worksheets visible and hidden as we navigate the user through the worksheets.  In all of our case studies, when the Workbook is initially opened, all (other than the “Welcome”) worksheets are hidden: –This is accomplished by using the Workbook_Open() event procedure which is executed on the open of the Workbook.

11 Figure 13.8  The following code hides all worksheets, but the welcome sheet, when the application is opened.

12 Ranges  Ranges will probably be the objects we use the most in VBA.  There are several properties and methods we will learn for Ranges; we will group them into the following categories. –Color format –Border format –Values –Font format –Clearing –Copy and PasteSpecial

13 Range: Color Format  To change the color of any range of cells, use the Interior property; there are a few sub properties we can then use –ColorIndex; value = numerical color index  3 = red  5 = blue  6 = yellow  4 = green –Color; value = VB Constant or RGB Function  vbRed, vbBlue, vbYellow, vbGreen  ( 255, 0, 0) = red  ( 0, 0, 255) = blue  ( 255, 255, 0) = yellow  ( 0, 255, 0) = green –Pattern, value = XL Constant  xlSolid, xlChecker, …

14 Figure  Let us create a solid, red range of cells on the “Welcome” sheet. Range(“A1:F12”).Interior.ColorIndex = 3 Range(“A1:F12”).Interior.Color = vbRed

15 Border Format  There is one main property and one main method we use to format range borders –Borders property –BordersAround method  The Borders property has several sub properties –LineStyle; value = xlDashed, xlSolid, … –Weight; value = xlThick, xlThin, … –Color; value = VB Constant, RGB Function –XL Constants = xlInsideHorizontal, xlEdgeBottom, …  The BordersAround method has several possible arguments –LineSytle:= xlDashed, xlSolid, … –Weight:= xlThick, xlThin, … –Color:= VB Constant, RGB Function

16 Figure  Let us format a table on the “Input” Worksheet.  We name the sub procedure Borders(). –Activate the “Input” worksheet. –Specify the range where we want our table to be located, followed by the Borders property. –If we type another period after the Borders property, we see a list of its sub properties.

17 Figures and  We make the LineStyle of the first row of our range dashed instead of solid.  We also modify the color of the second and third row’s borders by using the Color sub property.

18 Figure  Borders can also take predefined xl values to convey which set of borders should be modified.

19 Figure  We specify a new range and set the Borders property to xlInsideHorizontal so that each row of our range has a line above and below it.  We set the weight of this border to xlThick.

20 Figure  We use BorderAround method to set the line style and weight.  VBE provides us with a list of XL Constants for this argument’s values.

21 Figures and  Let us combine these properties, sub properties, and methods to format borders for several ranges of cells.

22 Values  Values are assigned to Ranges in VBA using the Value property.  The value of a range or cell can be –Text string –Numerical value –Basic Formula –Variable value

23 Figures and  Let us enter some different values into a spreadsheet.

24 Font Format  The Font property is used to format fonts of ranges.  There are several sub properties to use with the Font property. –Bold; value = True or False –Size; value = number –Color; value = VB Constant, RGB Function –ColorIndex; value = number –FontStyle; value = “style”

25 Figures and  Let us format the font of the values we just created by modifying the code.

26 Clearing  There are three common methods used to clear a range of cells. –Clear = clears everything –ClearContents = clears values or formulas only –ClearFormats = clears formats only  It is important to know which method is most appropriate for your worksheet.

27 Figures 13.28, 13.29, and  Let us apply some of the clearing methods to the table we created in Examples 4 and 5.

28 Conditional Formatting  Also associated with formatting the Range object is the FormatConditions object, which places conditional formatting on a specified range of cells.  There are three main methods and several properties for this object. –Add method –Modify method –Delete method

29 Figure  We place a conditional format on a range of cells so that: –Any cell with a value less than 10 becomes red: Range(“C1:C10”). ‑ FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, Formula1:=10 Range(“C1:C10”).FormatConditions(1).Interior.Color = vbRed –Any blank cell becomes yellow: Range(“C1:C10”). ‑ FormatConditions.Add Type:= xlBlanksCondition Range(“C1:C10”).FormatConditions(2).Interior.Color = vbYellow

30 Charts  Charts have many parameters which can be modified using VBA code.  The four main parts of the chart to manipulate are: –Chart Type –Source Data –Chart Options –Chart Location  The formatting of the chart can also be changed with VBA.

31 Two Chart Objects  When modifying charts with VBA, we will use two different chart objects –Charts –ActiveChart  The methods we will use with the Chart object are –Add; arguments = Before, After, Count –Copy –Delete –Select

32 Active Chart  The ActiveChart object will be used to set all other chart parameters and formatting.  Some main chart properties are –ChartType; value = XL Constants –HasLegend; value = True, False –HasTitle; value = True, False –ChartTitle; value = text name  Some main methods are –SetSourceData; arguments = Source, PlotBy –Location; arguments = Where, Name

33 Using Active Chart  Before using the ActiveChart object, we will need to Select or Add a particular Chart object.  When creating a new chart, we must set the four main parts of the chart using the following –Chart Type: ChartType –Source Data: SetSourceData –Chart Location: Location –Chart Options: HasLegend, HasTitle, etc.

34 Figures and  The Graph() procedure creates a chart from a table of data.

35 Further Chart Modification  We can modify the format of a chart using properties such as: –SeriesCollection  Add, Extend, HasDataLabels, Interior, ColorIndex  We can modify some chart parameters using methods such as: –ApplyCustomType; arguments = ChartType

36 Drawing Objects  Drawing objects, or shapes, can be useful to help the user visualize a problem scenario or suggested solution.  We can use the commands listed on the Insert > Illustration group on the Ribbon to draw a variety of shapes on the spreadsheet.  These objects can also be created and/or formatted in VBA code.  There are four main objects we use to create/format shapes in VBA. –ActiveSheet –Shape –Selection –ShapeRange

37 Creating Drawing Objects  There is one main method used to create a drawing object. –AddShape; arguments = Type, Left/Top, Width/Height  The Type argument can be equal to any MsoAutoShapeType  Left/Top sets the position of the shape in respect to the upper-left hand corner of the spreadsheet  Width/Height sets the width and height of the shape  This method is used with the Shapes object which is used with the Worksheets object (or ActiveSheet object).

38 Naming Drawing Objects  Naming drawing objects can greatly help in modifying them using VBA code.  To name a drawing object, we use the Name property.  First select an object in Excel to see what the default name is.  This is necessary so that you can select the appropriate shape first before naming it.  Then we will use the Select method for the Shapes object and then the Selection object to use the Name property.

39 Figures and  We can select and name a circle object.

40 Formatting Drawing Objects  We can use several different VBA properties to format drawing objects; these are a few. –Fill  ForeColor  SchemeColor –Line  Weight  EndArrowheadStyle, EndArrowheadWeight, EndArrowheadLength  BeginArrowheadStyle, BeginArrowheadWeight, BeginArrowheadLength  These properties are used with the ShapeRange object which is used with the Selection object.

41 Figures and  Suppose we have have created and named several circles and lines to make a network (of nodes and arcs). Let us format these drawing objects.

42 The Application Object  The Application object is useful for some common functions as well as some other features for running VBA code.  There are two main properties we will use for this object. –ScreenUpdating; value = True, False –CutCopyMode; value = True, False  There is also one main method we will use. –Wait; arguments = Now, TimeValue

43 The Application Object (cont’d)  The ScreenUpdating property helps the code run more efficiently since the Excel screen does not need to be updated after every action in the code.  The CutCopyMode property prevents a flashing box from remaining around the range which has been copied after a macro has been run.  These are both useful for example, when copying and pasting large data.

44 Figures 13.44, 13.45, and  Compare the results with and without the property CutCopyMode = False.

45 The Wait Method  The Wait method is frequently used when performing a Simulation in Excel.  Wait pauses the macro while it is being run until a specified time is reached. Application.Wait (Now + TimeValue())  The Now argument calculates the current time and the TimeValue argument gives an integer-valued time amount to add to the current time.  The macro will play again once Now plus TimeValue time is reached.

46 Figures and  Let us now format the two tables in our example.

47 The With Construct  The With construct is basically used to set several properties of one object in an enclosed statement.  For example, compare these two sets of code. Range(“A1:C8”).Interior.Color = vbRed Range(“A1:C8”).Font.Bold = True Range(“A1:C8”).Font.Name = “Arial” Range(“A1:C8”).Borders(xlEdgeBottom).LineStyle = xlDash With Range(“A1:C8”).Interior.Color = vbRed.Font.Bold = True.Font.Name = “Arial”.Borders(xlEdgeBottom). LineStyle = xlDash End With

48 Referencing and Names in VBA  Referencing ranges and cells  Naming ranges

49 Referencing and Names in VBA  As we have seen, the most common way to name an object in VBA is with the Name property.  There are several ways to reference ranges and cells using VBA. –Offset –Cells –Rows –Columns –EntireRow –EntireColumn –End

50 Offset vs Cells  The Offset property: –Considers the named range to be in the 0 th row and 0 th column. –It then offsets the range selection by a certain row count to above (if pos., below if neg.) and column count to the right (if pos., left if neg.) of this named range.  The Cells property: –Considers the named range to be in the 1 st row and 1 st column. –It then finds the cell in the x-th position above (if pos., below if neg.) and y-th position to the right (if pos., left if neg.) of the named range.

51 Figures and  Given data in an airline survey, we want to highlight certain columns of data using both the Offset and Cells properties comparatively.

52 Columns and Rows  Columns and Rows, reference columns and rows in our named range, respectively.  Both properties take a numerical index value to find the numbered column within the named range.  Both consider the first column or row in the range to be indexed as 1.

53 Figures and  We will now modify some more formatting of this table.

54 EntireColumn and EntireRow  EntireColumn and EntireRow, are used to modify every column or row in the named range for the length of the column or row of the entire worksheet.  The EntireColumn property will affect every column in the named range and the EntireRow property will affect every row in the named range for their entire respective length.

55 Figures and  We may use these properties on our table in preparation for future entries.

56 End  End is a very useful property as it can help you find the end of row or column of any range of data.  The End property can take four values: –xlDown and xlUp for columns –xlToRight and xlToLeft for rows  You do not need to name an entire data range to use this property, just one cell in the data range is fine.

57 Figures and  We will copy and paste our table using the End property.

58 Naming Ranges  The most common way to assign object names is by using the Name property.  When you name a range in Excel (using Formulas > Defined Names > Define Name command on the Ribbon), the name appears in the name window whenever the corresponding range is selected. The same occurs after naming a range in VBA.

59 Figure  If we now highlight the entire range of data in the row beginning with A3, we see the range name appear in the name window in the upper left hand corner of the window.

60 Figures and  Let us name a range and format one of its cells.

61 Formulas in VBA  Using the Range object  Using the Application object

62 Formulas with the Range Object  Two main properties can be used with the Range object –Formula; value = reference by column letter and row number –FormulaR1C1; value = reference by R1C1 Notation  A cell or an entire range of cells, or array, can be used with these properties.  There is also one method we can use with the Range object concerning formulas. –AutoFill; arguments = Destination, Type

63 Figure  We will calculate some sums and averages using both the Formula and FormulaR1C1 properties.  Since relative referencing is used, the formula will automatically modify for each relative row of data.

64 Figure  We use R1C1 Notation to calculate the average age of passengers in the table.

65 Figures and  We also use the AutoFill method to copy and paste formulas.

66 Formulas with Application Object  The Application object uses the WorksheetFunction property to set a function for a cell or range of cells.  The WorksheetFunction property has several sub properties for almost all of the Excel functions –Max –Min –Average –Sum –Count –VLookup

67 Figures and  Let us use these sub properties of the WorksheetFunction property to make some more calculations.

68 Summary  We study several methods and properties for the following objects –Workbooks and Worksheets –Ranges –Charts –Drawing Objects –Application  The With construct can help reduce code when modifying several properties of one object.  There are several properties of the Range object to reference ranges and cells.  Formulas can be created in VBA by using properties of the Range object and the Application object.

69 Additional Links  (place links here)