<excelunusual.com> Easy Zoom -Chart axis Scaling Using VBA - by George Lungu. <www.excelunusual.com> 1. Introduction: Chart naming: by George Lungu

Similar documents
Projectile Motion Tutorial #2 - animating the

A casual approach to numerical modeling

<excelunusual.com> Creating, Sizing, Translating and Rotating 2D Shapes in Excel by George Lungu. < 1

A Basic Flight Simulator in Excel #3 calculating the

- a 2D projectile motion model using numerical analysis of projectile dynamics (including aerodynamic drag) < by George Lungu1

Building a game of Tetris #1 the generation and the rotation of the Tetris parts

DATA 301 Introduction to Data Analytics Microsoft Excel VBA. Dr. Ramon Lawrence University of British Columbia Okanagan

Name: Dr. Fritz Wilhelm Lab 1, Presentation of lab reports Page # 1 of 7 5/17/2012 Physics 120 Section: ####

A Basic Flight Simulator in Excel #4 creating the initial,

Agenda. First Example 24/09/2009 INTRODUCTION TO VBA PROGRAMMING. First Example. The world s simplest calculator...

ICS Tutorials: Basic Operations

download instant at

Getting Started With Excel

Technology Assignment: Scatter Plots

PHLI Instruction (734) Introduction. Lists.

Download the files from you will use these files to finish the following exercises.

Starting Excel application

Chapter 3: Rate Laws Excel Tutorial on Fitting logarithmic data

Getting Started with DADiSP

USER MANUAL. AZI COMPUTRAC GRAPH for Microsoft Excel

Microsoft Excel 2016 Level 1

Excel window. This will open the Tools menu. Select. from this list, Figure 3. This will launch a window that

Lab1: Use of Word and Excel

Excel 2016: Introduction to VBA

DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6)

MDA V8.1 What s New Functionality Overview

Sub Programs. To Solve a Problem, First Make It Simpler

CSE 123 Introduction to Computing

LORD P.C.A.A LIONS MAT.HR.SEC SCHOOL, RESERVE LINE, SIVAKASI

Pre-Lab Excel Problem

Figure 1: Control & Simulation Loop

Three-Dimensional (Surface) Plots

MDA 8 preview SP3 What s New Functionality Overview

Understand and plan a chart Create a chart Move and resize charts and chart objects Apply chart layouts and styles

Gloucester County Library System EXCEL 2007

Today Function. Note: If you want to retrieve the date and time that the computer is set to, use the =NOW() function.

Excel 2. Module 3 Advanced Charts

Advance Excel Performing calculations on data 1. Naming groups of data 2. Creating formulas to calculate values

OPTIS Labs Tutorials 2013

239 Excel Keyboard Shortcuts

Fathom Tutorial. McGraw-Hill Ryerson Mathematics 11

Workbooks (File) and Worksheet Handling

Excel Simulations - 1

Macros enable you to automate almost any task that you can undertake

GCSE CCEA GCSE EXCEL 2010 USER GUIDE. Business and Communication Systems

ADVANCED EXCEL Course Modules for Advance Excel Training Online (MS Excel 2013 Course):

Advanced Financial Modeling Macros. EduPristine

Microsoft Excel 2010 Level 1

Outline. Midterm Review. Using Excel. Midterm Review: Excel Basics. Using VBA. Sample Exam Question. Midterm Review April 4, 2014

AEMLog Users Guide. Version 1.01

Statistics with a Hemacytometer

Customizing the Excel 2013 program window. Getting started with Excel 2013

San Francisco State University

Introduction to Microsoft Excel

Excel Manual X Axis Labels Below Chart 2010 Scatter

Read More: Index Function Excel [Examples, Make Dynamic Range, INDEX MATCH]

Excel tutorial Introduction

Microsoft Excel 2007 Lesson 7: Charts and Comments

Data Should Not be a Four Letter Word Microsoft Excel QUICK TOUR

Excel VBA. Microsoft Excel is an extremely powerful tool that you can use to manipulate, analyze, and present data.

Lab 7 Macros, Modules, Data Access Pages and Internet Summary Macros: How to Create and Run Modules vs. Macros 1. Jumping to Internet

Spreadsheet View and Basic Statistics Concepts

Changing Button Images in Microsoft Office

KEYWORDS DDE GETOBJECT PATHNAME CLASS VB EDITOR WITHEVENTS HMI 1.0 TYPE LIBRARY HMI.TAG

RECALLING PREVIOUS EXPRESSIONS

Rev Up to Excel 2010

Select the Points You ll Use. Tech Assignment: Find a Quadratic Function for College Costs

Microsoft Excel 2010 Basics

Years after US Student to Teacher Ratio

Acrobat 6.0 Standard - Basic Tasks

VBA Excel 2013/2016. VBA Visual Basic for Applications. Learner Guide

Models for Nurses: Quadratic Model ( ) Linear Model Dx ( ) x Models for Doctors:

Microsoft PowerPoint 2007 Tutorial

MS Excel VBA Class Goals

All Excel Topics Page 1 of 11

Plotting Graphs. Error Bars

Excel 2016 Intermediate for Windows

Workbooks & Worksheets. Getting Started. Formatting. Formulas & Functions

Ms Excel Vba Continue Loop Through Columns Range

Department of Chemical Engineering ChE-101: Approaches to Chemical Engineering Problem Solving Excel Tutorial VIII

Animation and Mechanization Tutorial

EXCEL 2007 GETTING STARTED

Microsoft Excel - Macros Explained

Microsoft Excel Level 1

Microsoft Excel Using Excel in the Science Classroom

Day : Date : Objects : Open MS Excel program * Open Excel application. Select : start. Choose: programs. Choose : Microsoft Office.

Project Manegment (IENG419) Fall: Research Assistants: Ehsan Shakeri, Mohammad Yazdi& Negar Akbarzadeh

Excel Programming with VBA (Macro Programming) 24 hours Getting Started

As you probably know, Microsoft Excel is an

Technical Documentation Version 7.3 Output

Reset Cursor Tool Clicking on the Reset Cursor tool will clear all map and tool selections and allow tooltips to be displayed.

Graphing with Excel. Mr. Heinrich/Mr. Flock R.O.W.V.A. High School, Oneida, IL Physics 4B

Macros enable you to automate almost any task that you can undertake

Reference and Style Guide for Microsoft Excel

Step-by. A Very Warm Welcome to the Exciting World of Computers. Let s get Started It s easy with my Step- Instructions

ECMWF New Users Metview Tutorial

Lines and Circles Guided Practice: Teacher Instructions

3D Surface Plots with Groups

Creating a Dynamo with VBA Scripts

Microsoft Excel 2007

Transcription:

Easy Zoom -Chart axis Scaling Using VBA - by George Lungu Introduction: - In certain models we need to be able to change the scale of the chart axes function of the result of a simulation - An Excel chart does have auto-scaling as a default option but sometimes the scaling values we get is not what we need. Another reason against using auto-scaling is that during the time the model runs, the scale self-adjusts and it gives an ever changing, distorted view of the results. A fast and easy manual zoom option is preferred. - This tutorial will handle that, namely it will create a VBA macro which can independently change chart axis scales between 1 to 10000 (in oscilloscope style: 1, 2, 5, 10, 20, 50, 100 ) Chart naming: - In order to have a macro change the format of an object (chart) we need to know the name of that object. The following macro will change the name of a chart to Chart_1 : Sub Rename() With ActiveChart.Parent.Name = "Chart 1" <excelunusual.com> by George Lungu <www.excelunusual.com> 1

<www.excelunusual.com> 2 How to use the macro: - Bring up the VBA editor (Alt+F11) and find the Rename macro - Select the chart you need to rename in the worksheet - Place the cursor inside the macro and click, then click the Run Sub/User Form button once - After this the chart is renamed. If you need to rename another chart make sure you change the name Chart_1 into something else The Scale_X macro: Run Sub/User Form button on the VBA editor menu - Bring up the control toolbox to create a button: View => Toolbars => Control Toolbox - Enter the design mode by clicking the upper left icon of the control toolbox - Drag draw a spin button, then right click it and bring up the properties menu - In the properties box change the (Name) to Scale_X - In the properties box change the Min to 1 and the Max to 13 - Exit the design mode by clicking the upper left icon of the control toolbox if you want to be able to use the macro

- Create a new button with the same properties as the previous one and name it Scale_Y - After creating the buttons write the following two macros in the VBA editor under the Rename macro (make sure to place the ax and ay variable declarations on top of the page above all the macros otherwise you get an error when you try to run the macro): Dim ax As Integer ----------------------------------------------------------------- Private Sub Scale_X_Change() If Scale_X.Value = 1 Then ax = 1 If Scale_X.Value = 2 Then ax = 2 If Scale_X.Value = 3 Then ax = 5 If Scale_X.Value = 4 Then ax = 10 If Scale_X.Value = 5 Then ax = 20 If Scale_X.Value = 6 Then ax = 50 If Scale_X.Value = 7 Then ax = 100 If Scale_X.Value = 8 Then ax = 200 If Scale_X.Value = 9 Then ax = 500 If Scale_X.Value = 10 Then ax = 1000 If Scale_X.Value = 11 Then ax = 2000 If Scale_X.Value = 12 Then ax = 5000 If Scale_X.Value = 13 Then ax = 10000.Axes(xlCategory).MinimumScale = 0.Axes(xlCategory).MaximumScale = ax Dim ay As Integer ----------------------------------------------------------------- Private Sub Scale_Y_Change() If Scale_Y.Value = 1 Then ay = 1 If Scale_Y.Value = 2 Then ay = 2 If Scale_Y.Value = 3 Then ay = 5 If Scale_Y.Value = 4 Then ay = 10 If Scale_Y.Value = 5 Then ay = 20 If Scale_Y.Value = 6 Then ay = 50 If Scale_Y.Value = 7 Then ay = 100 If Scale_Y.Value = 8 Then ay = 200 If Scale_Y.Value = 9 Then ay = 500 If Scale_Y.Value = 10 Then ay = 1000 If Scale_Y.Value = 11 Then ay = 2000 If Scale_Y.Value = 12 Then ay = 5000 If Scale_X.Value = 13 Then ay = 10000.Axes(xlValue).MinimumScale = 0.Axes(xlValue).MaximumScale = ay <www.excelunusual.com> 3

<www.excelunusual.com> 4 Excel screenshots: - The worksheet is named Easy_Zoom - The function on the chart is a plain f(x)= x function plotted in increments of 100 over 100 points within the C11:D110 range - Before clicking the two buttons make sure you are out of design mode - Verify the functionality by adjusting the buttons at different levels

Better Macros by the Use of Arrays: Jean-Marc, a visitor to my blog suggested the following macros in a comment: Dim ax As Integer Dim ay As Integer Dim arrscale As Variant Private Sub Scale_X_Change() arrscale = Array(1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000) ax = arrscale(scale_x.value - 1).Axes(xlCategory).MinimumScale = 0.Axes(xlCategory).MaximumScale = ax - Here arrscale is an array set to a fixed value within the macro - The array has 13 elements and any of them can be retrieved to be assigned to variable ax - In our case we use the value of Scale_X as the array argument and since the button sets the value of Scale_X between 1 and 13 we can retrieve any of the array s values between 1 and 10000 - Arrays have integer arguments starting with 0 (zero) and that s why you see the -1 in the argument: ax = arrscale(scale_x.value - 1) <www.excelunusual.com> 5

The second macro (the one scaling the Y axis looks similar): Private Sub Scale_Y_Change() arrscale = Array(1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000) ay = arrscale(scale_y.value - 1).Axes(xlValue).MinimumScale = 0.Axes(xlValue).MaximumScale = ay - A new worksheet called Easy_Zoom(array) has been created, which is identical to the old one but it s using the new array based VBA code. I used the Select-Case statement before to accomplish the same thing but the macro code is even more bloated than the one with several IF statements. Out of the three the array option is the best. Thanks, Jean-Marc! <www.excelunusual.com> 6