This content has been downloaded from IOPscience. Please scroll down to see the full text.

Similar documents
Lecture Notes on Mathematical Olympiad Courses

To link to this article: PLEASE SCROLL DOWN FOR ARTICLE

36TITE 140. Course Description:

Guide to Teaching Computer Science

TOURISM ECONOMICS AND POLICY (ASPECTS OF TOURISM) BY LARRY DWYER, PETER FORSYTH, WAYNE DWYER

A Practical Introduction to Teacher Training in ELT

MMOG Subscription Business Models: Table of Contents

International Series in Operations Research & Management Science

Following Directions. Table of Contents

Culture, Tourism and the Centre for Education Statistics: Research Papers

THE PROMOTION OF SOCIAL AWARENESS

Characteristics of the Text Genre Realistic fi ction Text Structure

Characteristics of the Text Genre Informational Text Text Structure

CHALLENGES FACING DEVELOPMENT OF STRATEGIC PLANS IN PUBLIC SECONDARY SCHOOLS IN MWINGI CENTRAL DISTRICT, KENYA

Characteristics of the Text Genre Informational Text Text Structure

LEARN TO PROGRAM, SECOND EDITION (THE FACETS OF RUBY SERIES) BY CHRIS PINE

CORRECT YOUR ENGLISH ERRORS BY TIM COLLINS DOWNLOAD EBOOK : CORRECT YOUR ENGLISH ERRORS BY TIM COLLINS PDF

Submission of a Doctoral Thesis as a Series of Publications

leading people through change

LEGO MINDSTORMS Education EV3 Coding Activities

Excel Formulas & Functions

Problem Solving for Success Handbook. Solve the Problem Sustain the Solution Celebrate Success

Houghton Mifflin Online Assessment System Walkthrough Guide

EDEXCEL FUNCTIONAL SKILLS PILOT. Maths Level 2. Chapter 7. Working with probability

Athens: City And Empire Students Book (Cambridge School Classics Project) By Cambridge School Classics Project

Background Information. Instructions. Problem Statement. HOMEWORK INSTRUCTIONS Homework #3 Higher Education Salary Problem

Designed by Candie Donner

ACTL5103 Stochastic Modelling For Actuaries. Course Outline Semester 2, 2014

Cambridge English First Masterclass Students Book

Practical Integrated Learning for Machine Element Design

TEACHER LEARNING AND LANGUAGE:

SkillPort Quick Start Guide 7.0

Copyright 2017 DataWORKS Educational Research. All rights reserved.

Dialogue Live Clientside

GO MATH TEACHER EDITION GRADE 6 PDF

Fractions Division And Multiplication Multiple Choice Test

McGraw-Hill Connect and Create Built by Blackboard. Release Notes. Version 2.3 for Blackboard Learn 9.1

Wolf Watch. A Degree Evaluation and Advising Tool. University of West Georgia

Fountas-Pinnell Level P Informational Text

D Road Maps 6. A Guide to Learning System Dynamics. System Dynamics in Education Project

JEFFERSON COLLEGE COURSE SYLLABUS BUS 261 BUSINESS COMMUNICATIONS. 3 Credit Hours. Prepared by: Cindy Rossi January 25, 2014

THE UNITED REPUBLIC OF TANZANIA MINISTRY OF EDUCATION, SCIENCE, TECHNOLOGY AND VOCATIONAL TRAINING CURRICULUM FOR BASIC EDUCATION STANDARD I AND II

McGraw-Hill Education Preparation For The GED Test 2nd Edition By McGraw-Hill Education Editors

Quick Start Guide 7.0

AUTONOMY. in the Law

Course Syllabus for Math

TEACHING Simple Tools Set II

Status of the MP Profession in Europe

Reviewed by Florina Erbeli

Answers To Hawkes Learning Systems Intermediate Algebra

Bitstrips for Schools: A How-To Guide

Accounting 380K.6 Accounting and Control in Nonprofit Organizations (#02705) Spring 2013 Professors Michael H. Granof and Gretchen Charrier

2013/Q&PQ THE SOUTH AFRICAN QUALIFICATIONS AUTHORITY

Using GIFT to Support an Empirical Study on the Impact of the Self-Reference Effect on Learning

IMPLEMENTING EUROPEAN UNION EDUCATION AND TRAINING POLICY

GEOMETRY CONCEPTS AND SKILLS ANSWERS PDF

Software Maintenance

A New Computing Book Series From ACM

Holt Mcdougal Pre Algebra Teachers Edition

More ESL Teaching Ideas

MARE Publication Series

PeopleSoft Human Capital Management 9.2 (through Update Image 23) Hardware and Software Requirements

The University of Texas at Tyler College of Business and Technology Department of Management and Marketing SPRING 2015

Early Childhood through Young Adulthood. (For retake candidates who began the Certification process in and earlier.)

Mcgraw Hill 2nd Grade Math

Practical Research Planning and Design Paul D. Leedy Jeanne Ellis Ormrod Tenth Edition

License to Deliver FAQs: Everything DiSC Workplace Certification

Implementation Science and the Roll-out of the Head Start Program Performance Standards

LBTS/CENTER FOR PASTORAL COUNSELING

Rubric For California Mission Project

CS 1103 Computer Science I Honors. Fall Instructor Muller. Syllabus

Mixed Up Multiplication Grid

Show and Tell Persuasion

Group Assignment: Software Evaluation Model. Team BinJack Adam Binet Aaron Jackson

POFI 1349 Spreadsheets ONLINE COURSE SYLLABUS

Conducting the Reference Interview:

Fountas-Pinnell Level M Realistic Fiction

Bot 2 Scoring Manual Download or Read Online ebook bot 2 scoring manual in PDF Format From The Best User Guide Database

Excel Intermediate

RCPCH MMC Cohort Study (Part 4) March 2016

Chamilo 2.0: A Second Generation Open Source E-learning and Collaboration Platform

Rover Races Grades: 3-5 Prep Time: ~45 Minutes Lesson Time: ~105 minutes

Instrumentation, Control & Automation Staffing. Maintenance Benchmarking Study

content First Introductory book to cover CAPM First to differentiate expected and required returns First to discuss the intrinsic value of stocks

Prof. Dr. Hussein I. Anis

Presentation Advice for your Professional Review

Mastering Biology Test Answers

Workkeys Study Guide Applied Technology

Flexible. Costeffective. Engaging. The BEST value science resource available. NEW app-based ebook. Assessment you can rely on. NEW Technician's Notes

ITM2500 Spreadsheet & Database Productivity. Spreadsheet & Database Productivity

Logical Soft Systems Methodology for Education Programme Development

Modern Chemistry Holt Rinehart And Winston

Software Development: Programming Paradigms (SCQF level 8)

NORMAL AND ABNORMAL DEVELOPMENT OF BRAIN AND BEHAVIOUR

Course Content Concepts

German Vocabulary (Quickstudy: Academic) By Inc. BarCharts

Introduce yourself. Change the name out and put your information here.

Road Maps A Guide to Learning System Dynamics System Dynamics in Education Project

Knowledge Synthesis and Integration: Changing Models, Changing Practices

Supplemental Focus Guide

Transcription:

This content has been downloaded from IOPscience. Please scroll down to see the full text. Download details: IP Address: 148.251.232.83 This content was downloaded on 22/02/2019 at 07:30 Please note that terms and conditions apply.

Excel VBA for Physicists A Primer

Excel VBA for Physicists A Primer Bernard V Liengme St Francis Xavier University, Nova Scotia, Canada Morgan & Claypool Publishers

Copyright ª 2016 Morgan & Claypool Publishers All rights reserved. No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without the prior permission of the publisher, or as expressly permitted by law or under terms agreed with the appropriate rights organization. Multiple copying is permitted in accordance with the terms of licences issued by the Copyright Licensing Agency, the Copyright Clearance Centre and other reproduction rights organisations. Rights & Permissions To obtain permission to re-use copyrighted material from Morgan & Claypool Publishers, please contact info@morganclaypool.com. Online supplementary data files are available at http://ej.iop.org/images/books/978-1-6817-4461-2/ live/bk978-1-6817-4461-2suppdata.zip ISBN ISBN ISBN 978-1-6817-4461-2 (ebook) 978-1-6817-4460-5 (print) 978-1-6817-4463-6 (mobi) DOI 10.1088/978-1-6817-4461-2 Version: 20161101 IOP Concise Physics ISSN 2053-2571 (online) ISSN 2054-7307 (print) A Morgan & Claypool publication as part of IOP Concise Physics Published by Morgan & Claypool Publishers, 40 Oak Drive, San Rafael, CA, 94903 USA IOP Publishing, Temple Circus, Temple Way, Bristol BS1 6HG, UK

To Pauline, my wife, my friend, and my amanuensis, with many, many thanks.

Contents Preface Acknowledgements Author biography x xi xii 1 Introduction 1-1 1.1 Preparation 1-1 1.2 Demonstrating a simple function 1-3 1.3 Saving a macro-enabled workbook 1-5 1.4 Using constants and VB functions 1-6 1.5 User-defined array function 1-7 1.6 Notes on VBA functions 1-8 1.7 A simple subroutine 1-9 1.8 Linking an image to a subroutine 1-11 1.9 Recording a macro 1-11 1.10 Finding a home for macros 1-14 1.11 Typographical matters 1-14 2 Variables, Dim statements, and data types 2-1 2.1 Naming variables 2-1 2.2 The Dim statement 2-1 2.3 The major reason for variable declarations 2-1 2.4 Declarations in function headers and for constants 2-3 2.5 Data types 2-3 2.6 A second reason for variable declarations 2-4 2.7 Dimensioning arrays 2-4 2.8 The Set statement 2-6 2.9 The With End With structure 2-7 3 Structured programming 3-1 3.1 Branching structures (If and Select Case) 3-1 3.2 Looping structures (For Next and Do While/Until) 3-4 3.3 Some further examples 3-7 vii

Excel VBA for Physicists 4 The Excel object model 4-1 4.1 Examples of properties, methods and events 4-1 4.2 The Range object properties 4-3 4.3 Range object methods 4-5 4.3.1 Select, Copy, and Paste 4-5 4.3.2 Clear methods 4-7 4.3.3 Delete method 4-7 4.4 WorksheetFunction object 4-7 4.5 Workbook and worksheet events 4-12 4.5.1 Workbook event 4-12 4.5.2 Worksheet event 4-13 4.6 Code for sending email 4-14 5 Working with add-ins 5-1 5.1 Creating an add-in 5-1 5.2 Installation 5-2 5.3 Using the add-in 5-2 5.4 Making changes to the add-in 5-3 5.5 Viewing worksheets 5-3 5.6 Protecting the add-in 5-4 5.7 Reversing everything 5-4 6 Numerical integration 6-1 6.1 The trapezoid approximation 6-1 6.2 The Simpson 1/3 approximation 6-4 6.3 An aside 6-6 6.4 Monte Carlo integration 6-7 6.5 Gaussian and Romberg integration 6-8 7 Numerical methods for differential equations 7-1 7.1 Euler s method 7-1 7.2 The Runge Kutta fourth-order method 7-4 7.3 Simultaneous OEDs 7-6 7.4 Example of a system of two OEDs 7-6 7.5 Higher order OEDs 7-8 7.6 R L circuit 7-8 viii

Excel VBA for Physicists 8 Finding roots 8-1 8.1 The bisection method 8-1 8.2 The successive iteration method 8-3 8.3 Root finding with Solver 8-4 8.4 Using range names 8-7 ix

Preface This work will introduce the reader to Visual Basic for Applications (VBA) and demonstrate how it can greatly enhance Microsoft Excel by giving users the ability to make their own functions that can be used within a worksheet, and to create subroutines to perform repetitive actions. Visual Basic (VB, the parent of VBA) has its roots in the educational programming language BASIC redeveloped at Dartmouth College in 1964. In the half-century since then, the language has evolved to become a high-powered object-orientated language which is no longer denigrated by aficionados of language such as C++ and C#. The VBA compiler and editor is incorporated within the Excel application; there is nothing to buy or install. The author s primary aim is to show the reader how to write both functions and subroutines, and to demonstrate that this is not a complex topic. The material is presented in a manner that will allow the reader to experiment with VBA programming; this is the best way to learn it. The scenarios used in the examples center around either fairly simple physics or non-complicated mathematics, such as root finding and numerical integration. The text, therefore, will be suitable not just for physicists but for other scientists and engineers, including students. A tested Excel workbook can be downloaded from here for each chapter. The brevity of the book prevents total rigour so it was necessary to condense some material, but Internet links are provided so the reader can explore VBA topics in greater depth. For the reader who prefers a paper reference source, Excel 2007 VBA by John Green et al (2007, New York: Wiley) is an excellent book, notwithstanding its date; furthermore, it can be obtained very cheaply online. The author is more than happy to reply to email inquiries about topics in the book or other Excel (with or without VBA) questions. Please use the word Excel in the subject line of each message. Have fun learning to extend Excel with VBA! Bernard V Liengme bliengme@stfx.ca x

Acknowledgements The author thanks Microsoft Excel Most Valuable Professionals (MVPs) Jon Peltier, Bob Umlas, and Jan Karel Pieterse for their help over the years. xi

Author biography Bernard V Liengme Bernard V Liengme attended Imperial College London for his undergraduate and postgraduate degrees; he held post-doctoral fellowships at Carnegie-Mellon University and the University of British Columbia. He has conducted extensive research in surface chemistry and the Mossbauer effect. He has been at St Francis Xavier University in Canada since 1968 as a Professor, Associate Dean, and Registrar, as well as teaching chemistry and computer science. He currently lectures part-time on business information systems. Bernard is also the author of other successful books: COBOL by Command (1996), A Guide to Microsoft Excel for Scientists and Engineers (now in its fourth edition), A Guide to Microsoft Excel for Business and Management (now in its second edition), Modelling Physics with Microsoft Excel (2014), and SMath for Physics: A Primer (2015). xii