Overview of Excel Object Model ISYS 562. Excel’s Database Tools Lookup and Database functions: –VLookUp, D functions Data –Sort –Filter –Subtotals –Pivot.

Slides:



Advertisements
Similar presentations
Sep-05 Slide:1 VBA in Excel Walter Milner. Sep-05 Slide:2 VBA in Excel Introduction VBA = Visual Basic for Applications Enables end-user programming In.
Advertisements

Chapter 10 Excel: Data Handling or What do we do with all that data?
MS-Word XP Lesson 7.
MS-Excel XP Lesson 2. Handling Worksheets 1.Bottom of the every workbook you can get worksheets. 2.No of sheets for a book is three. But you can add,
情報基礎 A Lecture 10 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.
Modeling using VBA. Covered materials -Userforms -Controls -Module -Procedures & Functions -Variables -Scope.
EXCEL VBA 101 Current Status Waiting Using Excel/VBA to Speed-up Daily Data Processing An Introduction to VBA Yongjun Chen Click Me to Start …
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.
Week 10.  Protecting Code  Protecting Worksheets  Error Handling  Charts.
Microsoft Excel. What is Microsoft Excel? Spreadsheet program that allows users to organize data, complete calculations, make decisions, and graph data.
1 Linking & Consolidating Worksheets Applications of Spreadsheets.
Using Macros and Visual Basic for Applications (VBA) with Excel
AE6382 VBA - Excel l VBA is Visual Basic for Applications l The goal is to demonstrate how VBA can be used to leverage the power of Excel u VBA syntax.
Tutorial 12: Enhancing Excel with Visual Basic for Applications
Tutorial 5: Working with Excel Tables, PivotTables, and PivotCharts
Chapter 5 Creating, Sorting, and Querying a Table
Creating Dashboard with Excel ISYS 650. Pivot Table Demo Creating a query from Northwind data warehouse that shows: –OrderYear, Quarter, CategoryID, Sales.
Database Features. Lists n An Excel worksheet can be used like a table in a relational database. n In Excel, such a table is called a list. n Each row.
Microsoft Excel 2010 Chapter 7
ActiveX Data Object ISYS 562. ADO An ActiveX control ActiveX is build upon COM, a contract that defines a standard interface by which objects communicate.
REVIEW Midterm Review ICS 101 Fall Inserting a Function.
Chapter 7 Data Management. Agenda Database concept Import data Input and edit data Sort data Function Filter data Create range name Calculate subtotal.
VBA Programming Session #2. Things to Review  Variables  Procedures: Subs & Functions  If…Then  For…Next.
Working with Charts ISYS 562. Chart Locations As an embedded object on a worksheet: –Worksheet ChartObjects –ChartObject: A container for a chart »Chart.
Introduction to Access BUS 782. Access Objects Tables –Open –Design –New –Wizard Queries Forms Reports Pages.
VBA & Excel Barry L. Nelson IEMS 465 Fall Quarter 2003.
Tutorial 5: Working with Excel Tables, PivotTables, and PivotCharts
Lab 9 – User Forms Design. User Forms What are user forms? –Known as dialog boxes –Major ways for getting user input An example of using user forms: Monthly.
University of Toronto at Scarborough © Andria Hunter, Kersti Wain-Bantin CSCA01 VBA-3 1 Lecture Outline Variable Scope Calling another subprogram Programming.
IN THE NAME OF ALLAH UserForms on VBA Lab 06 Tahani Al_dweesh.
Introduction on VBA Lab 05 ins.Tahani Al_dweesh. Lab Objectives Introduction Calculation with VBA Storing and Retrieving Variables in a Worksheet Using.
Office 2003 Advanced Concepts and Techniques M i c r o s o f t Excel Project 5 Creating, Sorting, and Querying a List.
Analysing Data with Excel Importing Data from a Text File To import data from a text file: 1.Start Excel. 2.Click File, click New, click Workbook,
PIVOT TABLES AND CHARTS CS1100 Computer Science and its Applications CS1100Pivot tables and charts1.
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.
With Excel 2007 Comprehensive 1e© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft Excel ® 2007 Comprehensive 1e Chapter.
Excel: Pivot Tables Exploring Computer Science Lesson Supplemental.
XP. Objectives Sort data and filter data Summarize an Excel table Insert subtotals into a range of data Outline buttons to show or hide details Create.
Chapter 9 Macros And Visual Basic For Applications.
Introduction to Excel VBA UNC Charlotte CPE/PDH Series December 17, 2009.
CREATING DATABASE Presenter: Jolanta Soltis. When to use Excel Use Excel when you: –Require a flat or non-relational view of your data (you do not need.
Lab 8 Data Access Using Microsoft ActiveX Data Object (ADO)
Spreadsheets What is Excel?. Objectives 1. Identify the parts of the Excel Screen 2. Identify the functions of a spreadsheet 3. Identify how spreadsheets.
Introduction to Access ISYS 363. Access Objects Tables –Open –Design –New –Wizard Queries Forms Reports Pages.
Review Excel Exam 1. Format Cell –Number –Alignment –Font –Border –Pattern –Protection Worksheet (group) Conditional formatting.
An electronic document that stores various types of data.
Microsoft ® Excel ® 2013 Enhanced Tutorial 5: Working with Excel Tables, PivotTables, and PivotCharts.
Excel Class Outline What is a spreadsheet? What can you do with them? The Cell - basic unit of a spreadsheet Making a Table - cells in Rows and Columns.
VBA Programming for Excel Review Excel Objects Excel Methods Identifying Specific Cells Review Functions for Excel Custom Menus.
Chapter 7 Creating Templates, Importing Data, and Working with SmartArt, Images, and Screen Shots Microsoft Excel 2013.
Microsoft Excel 2007 Noris Bt. Ismail Faculty of Information and Communication Technology Tel : (Ext 8408) BCOMP0101.
MSAA PRESENTS: AN EXCEL TUTORIAL
VBA - Excel VBA is Visual Basic for Applications
VBA - Excel VBA is Visual Basic for Applications
Exploring Computer Science Lesson Supplemental
Tutorial 5: Working with Excel Tables, PivotTables, and PivotCharts
Adam Little Catharine Reeder
Data Validation and Protecting Workbook
Excel for EMIS A few of my favorite things
Microsoft Excel.
Even More VBA IE 469 Spring 2017.
MS-Access (database) how to create blank data base.
Bryan College presents:
Visual Basic for Applications in Microsoft Excel (1)
Microsoft Excel 101.
Excel Import data from Access to Excel (ADO) using VBA
Pivot tables and charts
VBA Programming for Excel
Presentation transcript:

Overview of Excel Object Model ISYS 562

Excel’s Database Tools Lookup and Database functions: –VLookUp, D functions Data –Sort –Filter –Subtotals –Pivot table/Pivot chart OLAP: On Line Analytical Process DrillDown, RollUp –Import external data Import data New web query New database query ADO

Data/Import External Data New Database Query Select and click OK.

OLAP Cube Data/Import External Data/New database query: –Define query –In the last step, choose Create OLAP Cube

OLAP Wizard Source of data to be summarized Analysis dimensions

Web Query Data/Import External Data/New web query Click table on the web page Use the Save Query button to save web query Web query can be refreshed. Copy/Paste can not.

Import Data Data/Import External Data/Import Data

Excel Object Model

Excel Application –Workbooks/Workbook Worksheets –Worksheet »Range »Cells –Shapes »Drawing objects Charts »Chart User form

Workbooks Object Properties: –Count –Item Methods: –Add: Create a new, empty workbook –Open: This method opens an Excel file and creates a new workbook for the opened file. Workbooks.Open "c:\f.xls" –OpenDataBase: This method creates a new workbook and opens the database for import. Workbooks.OpenDatabase "C:\salesDB.mdb"

Workbook Object Properties: –ActiveChart, ActiveSheet –Charts, Sheets –ReadOnly, Password Methods: –Activate –RefreshAll –Save, SaveAs –Close

Worksheets Object Properties: –Count –Item Methods: –Add: –Delete: Worksheets("Sheet3").Delete –Copy –Move: Worksheets("Sheet1").Move after:=Worksheets("Sheet3") –Select

Worksheet Object Properties: –Cells –Columns: Worksheets("Sheet1").Columns(1).Font.Bold = True –ListObjects –Range –Rows: Worksheets("Sheet1").Rows(3).Delete –Shapes

Cells Cells(Index): –Index is cell’s sequence number. A1 – cells(1), B1 - Cells(2), C1 – cells(3). Cells(RowIndex, ColIndex) A1 – Cells(1,1), B3 – Cells(3, 2) Cells with no index: –All cells in a worksheet.

Cells Examples This example sets the font size for cell C5 on Sheet1 to 14 points: Worksheets("Sheet1").Cells(5, 3).Font.Size = 14 This example clears the formula in cell one on Sheet1: Worksheets("Sheet1").Cells(1).ClearContents Worksheets(1).Cells(1, 1).Value = 24 This example sets the font and font size for every cell on Sheet1 to 8-point Arial: With Worksheets("Sheet1").Cells.Font.Name = "Arial".Size = 8 End With The following example sets the formula for cell A2. ActiveSheet.Cells(2, 1).Formula = "=Sum(B1:B5)"

Cells with Loop This example loops through cells A1:J4 on Sheet1. If a cell contains a value less than 0.001, the example replaces that value with 0 (zero). For rwIndex = 1 to 4 For colIndex = 1 to 10 With Worksheets("Sheet1").Cells(rwIndex, colIndex) If.Value <.001 Then.Value = 0 End With Next colIndex Next rwIndex

Use ADO to Import A Table Private Sub CommandButton1_Click() Dim cn As ADODB.Connection Set cn = New ADODB.Connection cn.Open ("provider=microsoft.jet.oledb.4.0;data source=c:\salesDB.mdb;") Dim rs As ADODB.Recordset Set rs = New ADODB.Recordset rs.Open "select * from customer", cn, adOpenKeyset Dim i, j As Integer For i = 1 To rs.Fields.Count Sheet1.Cells(i) = rs.Fields(i - 1).Name Next i i = 2 Do While Not rs.EOF For j = 1 To rs.Fields.Count Sheet1.Cells(i, j) = rs.Fields(j - 1) Next j i = i + 1 rs.MoveNext Loop End Sub

Range Object Represents a cell, a row, a column, a selection of cells containing one or more contiguous blocks of cells, or a 3-D range.

Range Object Properties and Methods Properties: –CurrentRegion: The current region is a range bounded by any combination of blank rows and blank columns. –Formula –Value Methods: –Activate –AutoFormat –Clear –Delete –Select

Referring to a Range Use Range(arg), where arg names the range, to return a Range object that represents a single cell or a range of cells. The following example places the value of cell A1 in cell A5. –Worksheets("Sheet1").Range("A5").Value = 10 –Worksheets(“sheet1”).Range(“myRange”)=10 –Worksheets(“sheet1”).Range(“myRange”).Select The following example fills the range A1:H8 with random numbers by setting the formula for each cell in the range. When it’s used without an object qualifier (an object to the left of the period), the Range property returns a range on the active sheet. Use the Activate method to activate a worksheet before you use the Range property without an explicit object qualifier. –Worksheets("Sheet1").Activate –Range("A1:H8").Formula = "=Rand()"

Referring to a range as a collection of cells: –Cells.select, Cells(1).select –ActiveSheet.Cells(2, 1).Formula = "=Sum(B1:B5)" Referring to a range as collection of rows or columns: –Rows(2).select, Rows(“3:10”).select –Columns(3).select, Columns(“A:C”).select Referring to a range as current selection: –ActiveCell.CurrentRegion –Selection

Range Example Worksheets("faculty").Range("a1").Select ActiveCell.CurrentRegion.AutoFormat Format:=xlRangeAutoFormatClassic1 ActiveCell.CurrentRegion.Select MsgBox (Selection.Count)

Selection Property Returns the selected object in the active window, for an Application object, and a specified window, for a Windows object. The returned object type depends on the current selection (for example, if a cell is selected, this property returns a Range object). The Selection property returns Nothing if nothing is selected. Using this property with no object qualifier is equivalent to using Application.Selection. Example This example clears the selection on Sheet1 (assuming that the selection is a range of cells). Worksheets("Sheet1").Activate Selection.Clear

Workbook’s Charts Property Returns all chart sheets in the active workbook. –This example deletes every chart sheet in the active workbook. ActiveWorkbook.Charts.Delete –This example hides Chart1, Chart3, and Chart5. Charts(Array("Chart1", "Chart3", "Chart5")).Visible = False

Macro that Creates a Chart Sub CreateChart() Charts.Add ActiveChart.ChartType = xlColumnClustered ActiveChart.SetSourceData Source:=Sheets("faculty").Range("B1:C4"), PlotBy _ :=xlColumns ActiveChart.Location Where:=xlLocationAsNewSheet With ActiveChart.HasTitle = True.ChartTitle.Characters.Text = "Students".Axes(xlCategory, xlPrimary).HasTitle = True.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Faculty".Axes(xlValue, xlPrimary).HasTitle = True.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Number of Students" End With End Sub

VBA Procedure that Creates a Chart Dim newChart As Chart Set newChart = Charts.Add With newChart.ChartType = xl3DColumn.SetSourceData Source:=Sheets("faculty").Range("B1:C4"), PlotBy _ :=xlColumns.Location Where:=xlLocationAsNewSheet.HasTitle = True.ChartTitle.Characters.Text = "Students".Axes(xlCategory, xlPrimary).HasTitle = True.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Faculty".Axes(xlValue, xlPrimary).HasTitle = True End With

User Form

ListBox Properties: –RowSource: Source of listbox’s items. –ColumnCount: Number of columns in RowSource –BoundColumn: The column that contains the return value. Method: –ListBox1.AddItem ("customer")

SpinButton Max: Maximum value Min: Minimum value SmallChange: –Increment or decrement when click.

Pairing a Spinbutton with a Textbox Private Sub SpinButton1_Change() TextBox1.Text = SpinButton1.Value End Sub

OptionButton If OptionButton2 Then ListBox1.BoundColumn = 3 Else ListBox1.BoundColumn = 2 End If

ListBox RowSource

Code Example Private Sub UserForm_Activate() Worksheets("IntRate").Activate End Sub Private Sub SpinButton1_Change() TextBox1.Text = SpinButton1.Value End Sub Private Sub OptionButton1_Click() If OptionButton1 Then ListBox1.BoundColumn = 2 Else ListBox1.BoundColumn = 3 End If End Sub Private Sub OptionButton2_Click() If OptionButton2 Then ListBox1.BoundColumn = 3 Else ListBox1.BoundColumn = 2 End If End Sub

Private Sub ListBox1_Click() TextBox4.Text = ListBox1.Value End Sub Private Sub SpinButton1_Change() TextBox1.Text = SpinButton1.Value End Sub Private Sub CommandButton1_Click() Dim Term As Integer If OptionButton1 Then Term = 15 Else Term = 30 End If MsgBox (-Pmt(TextBox4.Value / 12, Term * 12, TextBox1.Value)) End Sub

MultiPage Control Properties: –Caption To add a new page: –Point to a page’s caption and right click, choose the New Page fom the context menu.

Events Workbook –VBE explorer: ThisWorkBook Open event –Private Sub Workbook_Open() UserForm1.Show –End Sub Worksheet –Activate event Private Sub Worksheet_Activate() UserForm1.Show End Sub