情報基礎 A Lecture 10 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.

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

Excel Object Model.
1B40: Data analysis 1 Objects Visual Basic is an (OO) object-oriented language. Performing a task in Visual Basic (VB) or.
Visual Basic for Applications (VBA) An object-oriented programming language –Instructions for the manipulation of objects –A structured way to provide.
Information literacy B Lecture 4 Database and Spreadsheet Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information.
ITEC 320 Lecture 3 In-class coding / Arrays. Arrays Review Strings –Advantages / Disadvantages Input –What two methods are used? Conditionals Looping.
Excel and Visual Basic. Outline Data exchange between Excel and Visual Basic. Programming VB in Excel.
情報基礎 B Lecture 5 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.
Object Oriented Programming A programming concept which views programs as objects with properties and ways to manipulate the object and the properties.
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 …
Week 10.  Protecting Code  Protecting Worksheets  Error Handling  Charts.
Chapter 13: More on Objects Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
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.
Excel VBA Class Glenn Harris Microsoft Certified Trainer Office Master Instructor Excel Class NYC.
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.
VBA Programming Session #2. Things to Review  Variables  Procedures: Subs & Functions  If…Then  For…Next.
Two-Dimensional Arrays School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 11, Friday 4/04/2003)
Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples.
VBA & Excel Barry L. Nelson IEMS 465 Fall Quarter 2003.
ADVANCED EXCEL FORMULAS 1 Lesson 8. Named Ranges Name a cell or a range of cells Can make formulas easy to understand =SUM(Sales) instead of =SUM(A2:A16)
Saeed Ghanbartehrani Summer 2015 Lecture Notes #3: Manipulating Excel Objects IE 212: Computational Methods for Industrial Engineering.
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.
# 1# 1 VBA Objects, Message Boxes as Functions What is an object in VBA? How do you move between design mode and run mode? How can you make a cell become.
情報基礎 A Lecture 15 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.
Creating Macros Using VBA. Assigning a Macro to a Button Display the Forms toolbar. Click the Button icon. Click and drag the mouse pointer to specify.
Introduction on VBA Lab 05 ins.Tahani Al_dweesh. Lab Objectives Introduction Calculation with VBA Storing and Retrieving Variables in a Worksheet Using.
Chapter 17: Arrays Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Lecture Excel: Macros & Pivot Tables. Macros A macro is a series of commands that are stored and can be run whenever you need to perform the task.
Class 3 Programming in Visual Basic. Class Objectives Learn about input/output Learn about strings Learn about subroutines Learn about arrays Learn about.
Excel exam on 10/24/2011 You may bring a single page cheat sheet with notes in front and back of the sheet Excel Review CS150 1.
情報基礎 B Lecture 8 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.
This is the first sheet of a spreadsheet workbook. The workbook begins initially with 3 work sheets. A spreadsheet is made of columns and rows. The intersection.
259 Lecture 13 Spring 2013 Advanced Excel Topics – Arrays.
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.
Intro to Excel Spreadsheets. Cell Reference (Cell Name) The unique identifier associated with a cell The unique identifier associated with a cell Combine.
CA I Excel Lesson 1. √Cells√Components√Other Terms active cell formula bar column cell name box label cell address Go To command row find range Excel.
OV Copyright © 2011 Element K Content LLC. All rights reserved.  Insert Text  Format Text  Sort Data  Duplicate Data  Generate a Report Formatting.
Multi-Dimensional Arrays Arrays that have more than one index: Example of differences between basic data types and arrays using integers: Basic integer:
Lab 4 Range Review, Control Logic and Loops ► Range Review ► Control Logic and Loops ► Exercise.
Excel 2010 Formatting Columns and Rows Excel 2010 / Mr. Bitenas In this lesson you will learn how to insert, delete, and resize Columns and Rows.
Microsoft Excel P.6 Computer Studies Chapter 1 – Introduction of Microsoft Excel What is Microsoft Excel? Microsoft Excel is a software for.
ME 142 Engineering Computation I Exam 2 Review VBA.
Data Structure CS 322. What is an array? Initializing arrays Accessing the values of an array Multidimensional arrays LAB#1 : Arrays.
Chapter 13: More on Objects Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Lab 2 Introduction to VBA (II) ► Lab 1 revisited - Sub & Function procedures - Data types and variable declaration ► Recording.
Lab 6 (2) Arrays ► Lab 5 (1) Exercise Review ► Array Concept ► Why Arrays? ► Array Declaration ► An Example of Array ► Exercise.
INTRODUCTION TO EXCEL Learning About Spreadsheets BTT 1O1.
Introduction to Excel VBA UNC Charlotte CPE/PDH Series December 17, 2009.
Visual Basic Objects / Properties / Methods PropertyAdjective ObjectNoun Part of the application Attribute MethodVerb Action to do something.
VBA Navigation, Conditionals, and Boxes. VBA Navigation.
Excel Basics. Differentiating between worksheets and spreadsheets Differentiating between workbooks and worksheets.
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.
مقدمة في البرمجة Lecture 7. Write VB.net project using the for loop to calculate : 1- the sum of numbers from 1 to (A) numbers. 2- the sum of Odd numbers.
情報基礎 A Lecture 9 Takeshi Tokuyama ・ Jinhee Chun Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis.
How to Create a form using the Program Excel By Mrs Douglas 8/1/10.
Excel Introduction to computers. Excel 2007 Starting the Excel program.
情報基礎 A Lecture 12 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.
Excel Tutorial 9th Grade FACS. Access Excel from the Start Menu.
Developing an Excel Applications
Two Dimensional Array Mr. Jacobs.
5. Using databases in VB.
Excel VBA Day 3 of 3 Tom Vorves.
Microsoft Excel 101.
Suppose I want to add all the even integers from 1 to 100 (inclusive)
Excel – VBA – How to use Non-Contiguous range of cells
Activate a range and manipulating activated range
情報基礎B   Lecture 7 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.
情報基礎B   Lecture 6 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.
Changing the Appearance of a Worksheet
Presentation transcript:

情報基礎 A Lecture 10 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information Systems

Programming VBA Cell Data

2-dimentional Array Integer Array x(9) Integer Array y(5) Integer Array z(5) Integer 2-dimentional Array a(5) x(9) y(9) z(9)

2-dimentional Array Declaration ArrayName(Max row index, Max column index ) Dim a(9,2) As Integer Array nameMaximum index number Data Type 2-dimentional Integer array Array name: a Number of box: 10*3=30

2-dimentional Array Declaration ArrayName(Row index range, Column index range) Dim a(1 to 10,1 to 3) As Integer Array nameIndex RangeData Type 2-dimentional Integer array Array name: a Number of box: 10*3=30

Cell Data Row number starts from 1 cells(row index, column index)

Cell format on Excel Range(“Column Row”) Cell Index : C2 Range(“C2”) or Cells(2,3) in VBA Range(“C2”) or Cells(2,3) in VBA Cells(Column index, Row index)

Procedure Code begins from “Sub” to end with “End Sub” 1Sub exercise1() 2 ThisWorkbook.Worksheets("Sheet1").Range("A:A").Value = 1 3End Sub 1Sub exercise2() 2 ThisWorkbook.Worksheets("Sheet1").Range("A:A").Interior.ColorIndex=4 3End Sub 1Sub exercise3() 2 ThisWorkbook.Worksheets("Sheet1").Range("A:A").Delete 3End Sub

Things to deal with in Excel –Worksheets, Cells, and more Object Period to connect objects Object Period to connect objects 1 ThisWorkbook. Worksheets("Sheet1"). Range("A:A"). Value = 1 1 ThisWorkbook. Worksheets("Sheet1"). Range("A:A"). Interior.ColorIndex = 4 1 ThisWorkbook. Worksheets("Sheet1"). Range("A:A"). Delete

Operation for object –Delete, Open and more Method Period to connect object and method Method Period to connect object and method 1 ThisWorkbook.Worksheets("Sheet1”).Range("A:A”).Delete

Attributes for object appearance Property Substitution Method Period to connect object and method Method Period to connect object and method 1ThisWorkbook.Worksheets(“Sheet1”).Range(“A:A”).Interior. ColorIndex = 3

Cell Reference –Range –Cells Set cell A10 to 10 –Both procedure below results the same 1Sub Example_Range1() 2 ActiveSheet.Range(“A1”).Value = 10 3End Sub 1Sub Example_Cells1() 2 ActiveSheet.Range(1, 1).Value = 10 3End Sub

Range Property Property to see an arbitrary cell or cell range –Read value –Set value Range(“Cell”) 1Sub Example_Range2() 2 ‘Set a value in cells 3 ActiveSheet.Range(“A1”).Value=10 4 ActiveSheet.Range(“A2”).Value=5 5 ActiveSheet.Range(“B1:B10”).Value=10 6End Sub

Cells Property See an arbitrary cell Cells(RowIndex,ColIndex) 1Sub Example_Cells2() 2 ‘Set a value in cells 3 ActiveSheet.Cells(1,5).Value=25 4 ActiveSheet.Cells(2,5).Value=5 5End Sub

Cells Property Procedure to set row number in cells F1- F100 Property ”.value” is omitted 1Sub Example_Cells3() 2 ‘Procedure to set row number in cells F1-F100 3 Dim i As Integer 4 5 For i = 1 to Cells(i, 6) = i 7 Next i 8End Sub

Sum of Cell A1 and A2 Output the sum of A1 and A2 to A3 with Range Output the sum of A1 and A2 to A4 with Cells 1Sub Example_Range3() 2 Range(“A3”) = Range(“A1”) + Range(“A2”) 3End Sub 1Sub Example_Cells3() 2 Cells(4,1) = Cells(1,1) + Cells(2,1) 3End Sub

Sum of Cells B1 to B10 Output the sum of B1 to B10 to B11 with Range 1Sub Example_Range4() 2 Range(“B11”) = Range(“B1”) + Range(“B2”) + Range(“B3”) + Range(“B4”) + Range(“B5”) + Range(“B6”) + Range(“B7”) + Range(“B8”) + Range(“B9”) + Range(“B10”) 3End Sub

Sum of Cells B1 to B10 Output the sum of B1 to B10 to B11 with Cells 1Sub Example_Cells5() 2 Dim i As Integer 3 Dim sum1 As Integer 4 sum1=0 5 6 For i = 1 to sum1 = sum1 + Cells(i, 2) 8 Next i 9 10 Cells(i, 2) = sum1 11End Sub