How To Code In Vba Vb.Io (For Ahem)

Similar documents
Using Loops to Repeat Code

Creating Basic Excel Formulas

3 IN THIS CHAPTER. Referring to Ranges. The Range Object The following is the Excel object hierarchy:

Writing Macros in Microsoft Excel 2003

Introduction. Syntax Statements. Colon : Line Continuation _ Conditions. If Then Else End If 1. block form syntax 2. One-Line syntax. Do...

Sample Table. Columns. Column 1 Column 2 Column 3 Row 1 Cell 1 Cell 2 Cell 3 Row 2 Cell 4 Cell 5 Cell 6 Row 3 Cell 7 Cell 8 Cell 9.

Financial Data Access with SQL, Excel & VBA

Construction Administrators Work Smart with Excel Programming and Functions. OTEC 2014 Session 78 Robert Henry

SPV Reporting Tool VBA Code User Guide. Last Updated: December, 2009

Word 2010: Mail Merge to with Attachments

RIT Installation Instructions

Module 2 - Multiplication Table - Part 1-1

USC Marshall School of Business Marshall Information Services

Microsoft Excel 2007 Mini Skills Overview of Tables

Commonly Used Excel Formulas

MICROSOFT ACCESS STEP BY STEP GUIDE

Microsoft Excel 2013 Step-by-Step Exercises: PivotTables and PivotCharts: Exercise 1

The Center for Teaching, Learning, & Technology

Excel Reporting with 1010data

What is Microsoft Excel?

Formulas & Functions in Microsoft Excel

Using GABRIEL Excel to XML Templates

Using Excel As A Database

Name = array(x,y,...,z) the indexing starts at zero, i.e. Name(0) = x. Programming Excel/VBA Part II (A.Fring)

Microsoft Excel 2010 Part 3: Advanced Excel

Macros allow you to integrate existing Excel reports with a new information system

Excel -- Creating Charts

warpct.com Working with MS Excel 2003 Workbook courseware by WARP! Computer Training

SOAL-SOAL MICROSOFT EXCEL 1. The box on the chart that contains the name of each individual record is called the. A. cell B. title C. axis D.

Welcome to the topic on Master Data and Documents.

Excel Level Two. Introduction. Contents. Exploring Formulas. Entering Formulas

The FTS Interactive Trader lets you create program trading strategies, as follows:

To add a data form to excel - you need to have the insert form table active - to make it active and add it to excel do the following:

Finding the last cell in an Excel range Using built in Excel functions to locate the last cell containing data in a range of cells.

Formulas & Functions in Microsoft Excel

Q&As: Microsoft Excel 2013: Chapter 2

ACCESS Importing and Exporting Data Files. Information Technology. MS Access 2007 Users Guide. IT Training & Development (818)

dtsearch Regular Expressions

Intro to Excel spreadsheets

Introduction to Microsoft Access 2003

Excel & Visual Basic for Applications (VBA)

Create Charts in Excel

Connecting to an Excel Workbook with ADO

To create a histogram, you must organize the data in two columns on the worksheet. These columns must contain the following data:

Excel 2003 Tutorial I

Formulas, Functions and Charts

Microsoft Excel 2013: Macro to apply Custom Margins, Titles, Gridlines, Autofit Width & Add Macro to Quick Access Toolbar & How to Delete a Macro.

Importing Data from a Dat or Text File into SPSS

Excel Functions (fx) Click the Paste Function button. In the Function Category select All. Scroll down the Function Name list And select SUM.

A Quick Guide to Using Excel 2007 s Regression Analysis Tool

In This Issue: Excel Sorting with Text and Numbers

A Quick Tour of F9 1

SPSS: Getting Started. For Windows

Excel Database Management Microsoft Excel 2003

Excel basics. Before you begin. What you'll learn. Requirements. Estimated time to complete:

How to Use SDTM Definition and ADaM Specifications Documents. to Facilitate SAS Programming

EXCEL XML SPREADSHEET TUTORIAL

Time Clock Import Setup & Use

Excel 2013 What s New. Introduction. Modified Backstage View. Viewing the Backstage. Process Summary Introduction. Modified Backstage View

Company Setup 401k Tab

EXCEL 2007 VLOOKUP FOR BUDGET EXAMPLE

LSP 121. LSP 121 Math and Tech Literacy II. Simple Databases. Today s Topics. Database Class Schedule. Simple Databases

As in the example above, a Budget created on the computer typically has:

Excel 2007 A Beginners Guide

Instructions for applying data validation(s) to data fields in Microsoft Excel

Microsoft Access 2010 Overview of Basics

Excel: Introduction to Formulas

Using Adobe Dreamweaver CS4 (10.0)

Loading Data into salesforce.com

Microsoft Using an Existing Database Amarillo College Revision Date: July 30, 2008

INTRODUCTION TO EXCEL

Anyone Can Learn PROC TABULATE

A User Manual for Benefit Cost Analysis Using Microsoft Excel

Using Excel s PivotTable to Analyze Learning Assessment Data

IENG2004 Industrial Database and Systems Design. Microsoft Access I. What is Microsoft Access? Architecture of Microsoft Access

Microsoft' Excel & Access Integration

Hands-on Exercise 1: VBA Coding Basics

Excel Working with Data Lists

SOME EXCEL FORMULAS AND FUNCTIONS

EXCEL Tutorial: How to use EXCEL for Graphs and Calculations.

1. Linking among several worksheets in the same workbook 2. Linking data from one workbook to another

Advanced Excel 10/20/2011 1

MICROSOFT WORD: MAIL MERGE

MICROSOFT EXCEL Formulas, Functions, & Macros. Documented by Vincent J. Yanusauskas Computer Training Coordinator

Advanced Microsoft Excel 2010

ECDL. European Computer Driving Licence. Spreadsheet Software BCS ITQ Level 2. Syllabus Version 5.0

Using Pivot Tables in Microsoft Excel 2003

The Basics of Microsoft Excel

BusinessObjects: General Report Writing for Version 5

Using Microsoft Excel 2010

Designed by Jason Wagner, Course Web Programmer, Office of e-learning ZPRELIMINARY INFORMATION... 1 LOADING THE INITIAL REPORT... 1 OUR EXAMPLE...

ACS Microcomputer Workshop Excel: Functions and Data Analysis Tools

Transcription:

Named Ranges To create a named range in VBA code you can use the Add method of the Names collection e.g., Names.Add Name:="ExamMarks", RefersTo:="=Exams!$A$2:$D$10" To select a named range that is on the active worksheet you can use Range("ExamMarks").Select To select a named range that is on another worksheet use Application.GoTo Reference:= "ExamMarks" The following doesn t work from a sheet other than the active sheet though it looks like it should Worksheets("Exams").Range("ExamMarks").Select

Named Ranges II To update the address of a named range after you have added/deleted rows just add the named range again with the updated address. If a range called ExamMarks has the address A2:D10 and you add three more rows of data then you could write Names.Add Name:="ExamMarks", RefersTo:="=Exams!$A$2:$D$13" In practice, an easier way to code this is to select the updated range and use Names.Add Name:="ExamMarks", RefersTo:= Selection or in short Names.Add "ExamMarks", Selection

Union Application.Union The Union method is used to select areas that are not adjacent, e.g., non adjacent columns Union(Columns("B"),Columns("E:H")).Select non adjacent cells Union(ActiveCell, ActiveCell.Offset(0,-3)).Select named ranges that are on the active sheet Union(Range("Food").Columns(2), Range("Drinks").Columns(2)) The Union operator The Union operator is, (comma) and can be used with the A1 referencing style as shown below Range("D1:E1, G1:J5").Select to select from the active cell to the last used cell on the sheet: Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select can be used on the rhs of an expression eg with WorksheetFunction var = WorksheetFunction.Max(Range("B2:B13"), Range("E2:E13"))

The Like operator Like is an operator that is used to match data on the worksheet which is in the form of a string e.g., If ActiveCell Like "ABC" Then Like is often used to partially match a string by using a wildcard in the expression e.g., If ActiveCell Like "A*" Then would evaluate to True if the value in the active cell begins with A The * stands for none, one or more characters. The other wildcard is? which stands for one character at the exact position e.g., Like "AA?" would match AAA AAa AAb but not AA

Range variables If you want to write the values from one range to another - the ranges must be the same size - you must use the value property e.g., Range("C22:C33").Value = Range("B2:B13").Value Typically one would use range variables: Sub test() Dim rng1 As Range, rng2 As Range Set rng1 = Range("C22:C33") Set rng2 = Range("B2:B13") rng1.value = rng2.value End Sub

Resize The Resize property of a range is used to resize its dimensions. The syntax is expression.resize(rowsize, ColumnSize) The example shows how to increase the size of a selection by one row: Selection.Resize(Selection.Rows.Count + 1).Select note that the reference to ColumnSize can be omitted if not needed

Row property For a single cell the Row property returns its Excel row number. For a selection, the Row property returns the Excel row number of the first cell in the selection, e.g., 5 in the illustration. Row is often used as part of some arithmetic. For example, if you needed to know how many blank rows are at top of the illustrated sheet ActiveSheet.UsedRange.Row - 1 would return 4

Various Calculating the number of the last row It s often necessary to calculate the last row number on a sheet, e.g., if you want to add new data to th e first empty row. Also a macro to delete rows is easier to write if you start with the last row and work upwards. An expression to determine the last Excel row number is ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count The Array function can be used to write multiple values to a range in one statement. e.g., Range("A1:D1") = Array("Name", "Phone", "Dept", "Course")

Cells property I There are advanced ways of using the Cells property. Given the selection illustrated, Selection.Cells(2,3) refers to cell C2 Because it is the second row, third column within the selection. For the same reason Range("A1:E6").Cells(2,3) refers to cell C2 this can be shortened to Range("A1").Cells(2,3) and further still to Range("A1")(2,3) This also applies to Named Ranges e.g., Range("ExamMarks")(2,3)

Cells property II It s easier to use the cells reference with a single parameter. Selection.Cells(1) refers to the first cell in a selection and this can be shortened to Selection(1) Similarly with Named Ranges Range("ExamMarks").Cells(1) or Range("ExamMarks")(1) Remember that Range("ExamMarks")(2) would go across as the range is two-dimensional. With a single cell or single column the reference is downwards Range("A20")(1) would reference A20 itself Range("A20")(2) would reference A21 You can use a variable like Range("A20")(i) with a For loop and achieve powerful and efficient code