Activate a range and manipulating activated range

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

Intermediate Formulas & Functions Instructor: Rachel Baltus.
Microsoft ® Office Excel ® 2003 Training Enter formulas CSNT, Inc. presents:
® Microsoft Office 2010 Excel Tutorial 1: Getting Started with Excel.
Introduction to Excel Formulas, Functions and References.
情報基礎 A Lecture 10 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.
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.
7-1 IS 2101 Spring 2010 Chapter 7 Managing Workbooks and Analyzing Data.
Tutorial 12: Enhancing Excel with Visual Basic for Applications
Exploring Microsoft Excel 2002 Chapter 8 Chapter 8 Automating Repetitive Tasks: Macros and Visual Basic for Applications By Robert T. Grauer Maryann Barber.
Introduction to VBA. This is not Introduction to Excel We’re going to assume you have a basic level of familiarity with Excel If you don’t, or you need.
Technology Basics Creating Worksheet Formulas. 2 Understand Formulas Equations used to calculate values in cells are called formulas. Formulas consist.
Excel 2007 Part (2) Dr. Susan Al Naqshbandi
CHAPTER 14 Formatting a Workbook Part 1. Learning Objectives Format text, numbers, dates, and time Format cells and ranges CMPTR Chapter 14: Formatting.
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.
Key Applications Module Lesson 16 — Excel Essentials Computer Literacy BASICS.
Week 3.  Assessed Exercise 1  Working with ranges.
 Starting Excel 2003  Using Help  Workbook Management  Cursor Management  Manipulating Data  Using Formulae and Functions  Formatting Spreadsheet.
CHAPTER 13 Creating a Workbook Part 2. Learning Objectives Work with cells and ranges Work with formulas and functions Preview and print a workbook 2.
® Microsoft Office 2010 Excel Tutorial 1: Getting Started with Excel.
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.
1 Microsoft Excel An Introduction to Spreadsheets Lecture 18.
IC 3 BASICS, Internet and Computing Core Certification Key Applications Lesson 11 Organizing the Worksheet.
Introduction to Excel Editing Your Workbook.
Formatting WorksheetsFormatting Worksheets Lesson 7.
Excel Web App By: Ms. Fatima Shannag.
The Object Model. You can think of the contents of an Excel application as a hierarchy of collections of objects, manipulated by code Each object can.
Chapter 13: More on Objects Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Microsoft Excel. Excel specializes in creating and designing spreadsheets, or worksheets Worksheet – area to insert data Workbook – a set of worksheets.
Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Lesson 6 Formatting Cells and Ranges. Objectives:  Insert and delete cells  Manually format cell contents  Copy cell formatting with the Format Painter.
Spreadsheets What is Excel?. Objectives 1. Identify the parts of the Excel Screen 2. Identify the functions of a spreadsheet 3. Identify how spreadsheets.
CONDITIONAL FORMATTING AND CUSTOM NUMBER FORMATS LEC 5 1.
Computer Fundamentals Muhammadamin Daneshwar And Masoud Aras Computer Engineering Department Soran University Lecture 6.
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.
COMPREHENSIVE Excel Tutorial 12 Expanding Excel with Visual Basic for Applications.
Day 2: MS Excel for Beginners Aniko Balogh CEU Computer & Statistics Center
Chapter 3: Basic Excel Skills
Lecturer: Dalia Mirghani
GO! with Microsoft Office 2016
Microsoft Excel Illustrated
Working with Multiple Workbooks
Excel Training - Part One
Created by Stacey Wilson
Formatting a Worksheet
Spreadsheet-Based Decision Support Systems
Objectives Format text, numbers, and dates
Microsoft Excel A Spreadsheet Program.
European Computer Driving Licence
MS-Excel Part 1.
Lessons Vocabulary Excel 2016.
Microsoft Excel 2003 Illustrated Complete
Learning Excel Session 9 and 10 Dr. Chaitali Basu Mukherji.
Formatting a Worksheet
Creating a Workbook Part 2
Formatting a Worksheet
Test Review: Intro to Excel Test date Monday 11/27
Creating Macros in Excel
Exploring Microsoft Excel
Lesson 18 Getting Started with Excel Essentials
Using Charts in a Presentation
Formatting a Workbook Part 1
Navya Thum January 23, 2013 Day 3: MICROSOFT EXCEL Navya Thum January 23, 2013.
Lesson 1 - Automating Tasks
Key Applications Module Lesson 16 — Excel Essentials
Unit G: Using Complex Formulas, Functions, and Tables
Microsoft Excel 2007 – Level 2
Exploring Microsoft Excel 2003
Presentation transcript:

ExCEL Macro (part 1I) 1. Activate a range and manipulating activated range 2.Offset 3. Int

Activate a range and manipulating activated range Here are a few examples of commonly used collections: ✓ Workbooks: A collection of all currently open Workbook objects ✓ Worksheets: A collection of all Worksheet objects contained in a particular Workbook object ✓ Charts: A collection of all Chart objects (chart sheets) contained in a particular Workbook object ✓ Sheets: A collection of all sheets

Activate a range and manipulating activated range You can work with an entire collection of objects in one fell swoop. More often, however, you need to work with a specific object in a collection (such as a particular worksheet in a workbook). To reference a single object from a collection, you put the object’s name or index number in parentheses after the name of the collection, like this: If Sheet1 is the first (or only) worksheet in the collection, you can also use the following reference:

Activate a range and manipulating activated range Navigating through the hierarchy If you want to work with the Application object, it’s easy: You start by typing Application. To navigate farther to a specific worksheet, add a dot operator and access the Worksheets collection object. Not far enough yet? If you really want to get the value from cell A1 on the first Worksheet of the Workbook named Book1.xlsx, you need to navigate one more level to the Range object.

Activate a range and manipulating activated range Every object has properties. You can think of properties as attributes that describe the object. An object’s properties determine how it looks, how it behaves, and even whether it is visible. Using VBA, you can do two things with an object’s properties: ✓ Examine the current setting for a property. ✓ Change the property’s setting.

Activate a range and manipulating activated range For example, a single-cell Range object has a property called Value. The Value property stores the value contained in the cell. You can write VBA code to display the Value property, or you may write VBA code to set the Value property to a specific value. The following macro uses the VBA builtin MsgBox function to bring up a box that displays the value in cell A1 on Sheet1 of the active workbook.

Activate a range and manipulating activated range In addition to properties, objects have methods. A method is an action you perform with an object. A method can change an object’s properties or make the object do something. This simple example uses the ClearContents method on a Range object to erase the contents of 12 cells on the active sheet:

Activate a range and manipulating activated range The following example activates Sheet1 (in the active workbook) and then copies the contents of cell A1 to cell B1 by using the Range object’s Copy method. In this example, the Copy method has one argument — the destination range for the copy operation:

Activate a range and manipulating activated range Another way to specify an argument for a method is to use the official name of the argument followed by a colon and an equal sign. Using named arguments is optional, but doing so can often make your code easier to understand. The second statement in the CopyOne procedure could be written like this:

The Offset property The Offset property provides another handy means for referring to ranges. This property, which operates on a Range object and returns another Range object, lets you refer to a cell that is a particular number of rows and columns away from another cell. Like the Cells property, the Offset property takes two arguments. The first argument represents the number of rows to offset; the second represents the number of columns to offset. The following expression refers to a cell one row below cell A1 and two columns to the right of cell A1. In other words, this refers to the cell commonly known as C2:

The Offset property The Offset property can also use negative arguments. A negative row offset refers to a row above the range. A negative column offset refers to a column to the left of the range. The following example refers to cell A1: And, as you may expect, you can use 0 as one or both of the arguments for Offset. The following expression refers to cell A1: Here’s a statement that inserts the time of day into the cell to the right of the active cell:

The Interior property Here’s yet another example of a property that returns an object. A Range object’s Interior property returns an Interior object (strange name, but that’s what it’s called). For example, the following statement changes the Color property of the Interior object contained in the Range object: In other words, this statement changes the cell’s background to middle gray. What’s that? You didn’t know that 8421504 is middle gray? For some insights into Excel’s wonderful world of color, see the nearby sidebar “A quick and dirty color primer.”

The Interior property You can perform copy and paste operations in VBA by using the Copy and Paste methods. Note that two different objects come into play. The Copy method is applicable to the Range object, but the Paste method applies to the Worksheet object. It actually makes sense: You copy a range and paste it to a worksheet.

The Interior property Notice that in the preceding example, the ActiveSheet object is used with the Paste method. This is a special version of the Worksheet object that refers to the currently active worksheet. Also notice that the macro selects the range before copying it. However, you don’t have to select a range before doing something with it. In fact, the following procedure accomplishes the same task as the preceding example by using a single statement:

The Interior property The Clear method The Clear method deletes the contents of a range, plus all the cell formatting. For example, if you want to zap everything in column D, the following statement does the trick: You should be aware of two related methods. The ClearContents method deletes the contents of the range but leaves the formatting intact. The ClearFormats method deletes the formatting in the range but not the cell contents.

The Interior property The Delete method Clearing a range differs from deleting a range. When you delete a range, Excel shifts the remaining cells around to fill up the range you deleted. The following example uses the Delete method to delete row 6: The following statement deletes a range and then fills the resulting gap by shifting the other cells to the left: