This document provides instructions and tutorials for a lab on Visual Basic and spreadsheet programming basics. The lab consists of three tutorials that students should complete during the lab session or on their own time. The tutorials cover topics like creating macros, recording macros, modules and procedures, objects and collections in VBA, and the Range and Cells objects. Students are expected to work through examples and tasks in each tutorial. Their understanding of the material will be assessed on an upcoming Excel exam.
Customizing Xcos with new Blocks and PaletteScilab
In this tutorial, we show how to create and customize Xcos blocks and palettes. Moreover, we use the "Xcos toolbox skeleton" for a better result. The LHY model in Xcos scheme (already developed in other tutorials) is used as a starting point.
Customizing Xcos with new Blocks and PaletteScilab
In this tutorial, we show how to create and customize Xcos blocks and palettes. Moreover, we use the "Xcos toolbox skeleton" for a better result. The LHY model in Xcos scheme (already developed in other tutorials) is used as a starting point.
High-Level Display: Screen J2ME User Interfacesuman sinkhwal
The display is a crucial component of every J2ME application since it contains objects used to present information to the person using the application and in many cases prompts the person to enter information that is processed by the application. You were introduced to the basic concepts of the J2ME display in the previous chapter and shown how to create a simple graphical user interface for your application. To say the least, this user interface is wanting and lacks sophistication that most of us expect from a J2ME application.
This is a presentation which is used in Healthcare IT Professional (HITP) course.
The goal is to show the student how data can be organized and manipulated (drill down, slice and dice..) using Excel.
This part comes after introduction to data warehouse and OLAP.
www.alamedaservices.com
The presentation was the fourth webinar in a series of discussions on the popular MEASURE Evaluation manual, How Do We Know If a Program Made a Difference? A Guide to Statistical Methods for Program Impact Evaluation. The webinar was also referred to as "Within Estimators."
Parametric vs Nonparametric Tests: When to use whichGönenç Dalgıç
There are several statistical tests which can be categorized as parametric and nonparametric. This presentation will help the readers to identify which type of tests can be appropriate regarding particular data features.
High-Level Display: Screen J2ME User Interfacesuman sinkhwal
The display is a crucial component of every J2ME application since it contains objects used to present information to the person using the application and in many cases prompts the person to enter information that is processed by the application. You were introduced to the basic concepts of the J2ME display in the previous chapter and shown how to create a simple graphical user interface for your application. To say the least, this user interface is wanting and lacks sophistication that most of us expect from a J2ME application.
This is a presentation which is used in Healthcare IT Professional (HITP) course.
The goal is to show the student how data can be organized and manipulated (drill down, slice and dice..) using Excel.
This part comes after introduction to data warehouse and OLAP.
www.alamedaservices.com
The presentation was the fourth webinar in a series of discussions on the popular MEASURE Evaluation manual, How Do We Know If a Program Made a Difference? A Guide to Statistical Methods for Program Impact Evaluation. The webinar was also referred to as "Within Estimators."
Parametric vs Nonparametric Tests: When to use whichGönenç Dalgıç
There are several statistical tests which can be categorized as parametric and nonparametric. This presentation will help the readers to identify which type of tests can be appropriate regarding particular data features.
Business today is starting to understand the value of data, and some organisations are outperforming their competition by putting data at the heart of their thinking. Leveraging data to change business models, understand their customers and employees better and deliver new revenue streams is the driving force in this new data centric era.
Jon Woodward - MSFT
Dave Coplin - MSFT
Mike Bugembe - JustGiving
Gary Richardson - KPMG
Learn VBA Training & Advance Excel Courses in Delhiibinstitute0
Investment Banking Institute (IBI) is the one of the most accepted & highly reputed institute of investment banking education which offers both online and corporate training of basic & advance excel 2010, financial modeling & company valuation, VBA training. Weekend classes of financial modeling & advance excel training in Delhi are provided by this reputed corporate banking institute to professionals & students at an outstanding level.
A macro is a set of commands that can be played back at will to perform a given task. These tasks can be something simple such as inserting your name and address into a word processor to something more complex such as launching a program, copying data from it, activating another program, pasting the data into it and repeating this several times. Tasks performed by macros are typically repetitive in nature allowing significant savings in time by executing the macro instead of manually repeating the commands.
Online Advance Excel & VBA Training in Indiaibinstitute0
In today’s era, Investment banking courses are considered as the best path to make bright future. These courses includes financial modeling training, basic & advance excel training, excel dashboard 2010 course, financial modeling & company valuation training, relative valuation etc. Investment banking Institute (IBI) in Delhi provides such types of training of best level in weekend classes. IB Institute provides Online & corporate financial modeling & company valuation training in Delhi, India.
Whether you are a senior manager, a project manager, a finance guy, a sales head, executive, marketing professional, operations or anyone who deals with numbers. We all need excel and we all have heard about MS Excel Macros. But most of us do not know how to write one or where to start from. This tutorial is a great starting point for quickly learning how to write your first Excel Macro so that you can get started on your own. So go ahead, check it out and have fun. Cheers.
Software engineering modeling lab lectures
engineering+ education purpose
This series of lectures was prepared for the third class of software engineering / Aliraqia University/ Baghdad/ Iraq.
In prepared these lectures, I depend on the YouTube to make it, the programs of the lectures are designed and executed by vb.net, discussions are also found here
These lectures are not finished yet, i will improve it in the future
Forgive me for anything wrong by mistake, I wish you can profit from these lectures
My regard
Marwa Moutaz/ M.Sc. studies of Communication Engineering / University of Technology/ Bagdad / Iraq.
It covers all the basics of MATLAB required for beginners. After going through these slides, anyone can write a MATLAB program and apply it to his field of interest.
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
Are you looking to streamline your workflows and boost your projects’ efficiency? Do you find yourself searching for ways to add flexibility and control over your FME workflows? If so, you’re in the right place.
Join us for an insightful dive into the world of FME parameters, a critical element in optimizing workflow efficiency. This webinar marks the beginning of our three-part “Essentials of Automation” series. This first webinar is designed to equip you with the knowledge and skills to utilize parameters effectively: enhancing the flexibility, maintainability, and user control of your FME projects.
Here’s what you’ll gain:
- Essentials of FME Parameters: Understand the pivotal role of parameters, including Reader/Writer, Transformer, User, and FME Flow categories. Discover how they are the key to unlocking automation and optimization within your workflows.
- Practical Applications in FME Form: Delve into key user parameter types including choice, connections, and file URLs. Allow users to control how a workflow runs, making your workflows more reusable. Learn to import values and deliver the best user experience for your workflows while enhancing accuracy.
- Optimization Strategies in FME Flow: Explore the creation and strategic deployment of parameters in FME Flow, including the use of deployment and geometry parameters, to maximize workflow efficiency.
- Pro Tips for Success: Gain insights on parameterizing connections and leveraging new features like Conditional Visibility for clarity and simplicity.
We’ll wrap up with a glimpse into future webinars, followed by a Q&A session to address your specific questions surrounding this topic.
Don’t miss this opportunity to elevate your FME expertise and drive your projects to new heights of efficiency.
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualityInflectra
In this insightful webinar, Inflectra explores how artificial intelligence (AI) is transforming software development and testing. Discover how AI-powered tools are revolutionizing every stage of the software development lifecycle (SDLC), from design and prototyping to testing, deployment, and monitoring.
Learn about:
• The Future of Testing: How AI is shifting testing towards verification, analysis, and higher-level skills, while reducing repetitive tasks.
• Test Automation: How AI-powered test case generation, optimization, and self-healing tests are making testing more efficient and effective.
• Visual Testing: Explore the emerging capabilities of AI in visual testing and how it's set to revolutionize UI verification.
• Inflectra's AI Solutions: See demonstrations of Inflectra's cutting-edge AI tools like the ChatGPT plugin and Azure Open AI platform, designed to streamline your testing process.
Whether you're a developer, tester, or QA professional, this webinar will give you valuable insights into how AI is shaping the future of software delivery.
UiPath Test Automation using UiPath Test Suite series, part 3DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 3. In this session, we will cover desktop automation along with UI automation.
Topics covered:
UI automation Introduction,
UI automation Sample
Desktop automation flow
Pradeep Chinnala, Senior Consultant Automation Developer @WonderBotz and UiPath MVP
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Securing your Kubernetes cluster_ a step-by-step guide to success !KatiaHIMEUR1
Today, after several years of existence, an extremely active community and an ultra-dynamic ecosystem, Kubernetes has established itself as the de facto standard in container orchestration. Thanks to a wide range of managed services, it has never been so easy to set up a ready-to-use Kubernetes cluster.
However, this ease of use means that the subject of security in Kubernetes is often left for later, or even neglected. This exposes companies to significant risks.
In this talk, I'll show you step-by-step how to secure your Kubernetes cluster for greater peace of mind and reliability.
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
Here is something new! In our next Connector Corner webinar, we will demonstrate how you can use a single workflow to:
Create a campaign using Mailchimp with merge tags/fields
Send an interactive Slack channel message (using buttons)
Have the message received by managers and peers along with a test email for review
But there’s more:
In a second workflow supporting the same use case, you’ll see:
Your campaign sent to target colleagues for approval
If the “Approve” button is clicked, a Jira/Zendesk ticket is created for the marketing design team
But—if the “Reject” button is pushed, colleagues will be alerted via Slack message
Join us to learn more about this new, human-in-the-loop capability, brought to you by Integration Service connectors.
And...
Speakers:
Akshay Agnihotri, Product Manager
Charlie Greenberg, Host
JMeter webinar - integration with InfluxDB and GrafanaRTTS
Watch this recorded webinar about real-time monitoring of application performance. See how to integrate Apache JMeter, the open-source leader in performance testing, with InfluxDB, the open-source time-series database, and Grafana, the open-source analytics and visualization application.
In this webinar, we will review the benefits of leveraging InfluxDB and Grafana when executing load tests and demonstrate how these tools are used to visualize performance metrics.
Length: 30 minutes
Session Overview
-------------------------------------------
During this webinar, we will cover the following topics while demonstrating the integrations of JMeter, InfluxDB and Grafana:
- What out-of-the-box solutions are available for real-time monitoring JMeter tests?
- What are the benefits of integrating InfluxDB and Grafana into the load testing stack?
- Which features are provided by Grafana?
- Demonstration of InfluxDB and Grafana using a practice web application
To view the webinar recording, go to:
https://www.rttsweb.com/jmeter-integration-webinar
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
UiPath Test Automation using UiPath Test Suite series, part 4DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 4. In this session, we will cover Test Manager overview along with SAP heatmap.
The UiPath Test Manager overview with SAP heatmap webinar offers a concise yet comprehensive exploration of the role of a Test Manager within SAP environments, coupled with the utilization of heatmaps for effective testing strategies.
Participants will gain insights into the responsibilities, challenges, and best practices associated with test management in SAP projects. Additionally, the webinar delves into the significance of heatmaps as a visual aid for identifying testing priorities, areas of risk, and resource allocation within SAP landscapes. Through this session, attendees can expect to enhance their understanding of test management principles while learning practical approaches to optimize testing processes in SAP environments using heatmap visualization techniques
What will you get from this session?
1. Insights into SAP testing best practices
2. Heatmap utilization for testing
3. Optimization of testing processes
4. Demo
Topics covered:
Execution from the test manager
Orchestrator execution result
Defect reporting
SAP heatmap example with demo
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Albert Hoitingh
In this session I delve into the encryption technology used in Microsoft 365 and Microsoft Purview. Including the concepts of Customer Key and Double Key Encryption.
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on the notifications, alerts, and approval requests using Slack for Bonterra Impact Management. The solutions covered in this webinar can also be deployed for Microsoft Teams.
Interested in deploying notification automations for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
A presentation about the usage and availability of Varnish on Kubernetes. This talk explores the capabilities of Varnish caching and shows how to use the Varnish Helm chart to deploy it to Kubernetes.
This presentation was delivered at K8SUG Singapore. See https://feryn.eu/presentations/accelerate-your-kubernetes-clusters-with-varnish-caching-k8sug-singapore-28-2024 for more details.
Accelerate your Kubernetes clusters with Varnish Caching
Excel Vba Basic Tutorial 1
1. Department of Mechanical and Manufacturing Engineering
Schulich School of Engineering
University of Calgary
Computing Tools for Engineering Design (ENME 337 H(3-2))
Instructor:
Dr. Alejandro Ramirez-Serrano
Office: ME420 , Phone: 220-3632
E-mail: aramirez@enme.ucalgary.ca
Laboratory No. 2
“Visual Basic and Spreadsheet Programming Basics”
Instructions:
This lab consists of three tutorials. During the lab you should work on all three tutorials one by one. Start
with the first tutorial and work until you complete all three tutorials. If you cannot complete the all tutorials
tasks by the end of the lab session you are responsible for completing the tasks at your own spare time.
There is no lab report to be submitted, however, the material covered in the lab sessions will be included in
the Excel midterm exam. Thus, students are responsible for completing the lab.
Excel VBA Basic Tutorial 1
This page contains the 1st lesson on the Excel VBA Basic Tutorial series. It covers topics in creating and managing
array and understanding the VBA decision and loop structures. Beginners in VBA programming are encouraged to
go through the prior lessons in this series if they had not already done so. This document contains information about
the following topics.
• Creating Your First Macro
• Recording Your First Macro
Recording a Marco
See the Recorded Syntax
Run the Recorded Marco
• Modules and Procedures
Modules and Procedures and Their Scope
Calling Sub Procedures and Function Procedures
Passing Arguments by Value or by Reference
Microsoft Support site or the Excel VBA Help section on your computer contains comprehensive examples on most
the issues covered on this page. For more information, please refer to them.
Creating Your First Macro
1
2. In this sub section, we will show you how to create your first macro (VBA program). We will use the world classic
quot;Hello World!quot; example. To create the example, please follow the following steps:
1. Open Visual Basic Editor by go to Tools...Macro ...Visual Basic Editor or just simply press the [Alt]
and [F11] keys at the same time.
2. In the Insert menu on top of the Visual Basic Editor, select Module to open the Module window (code
window).
3. In the Module window, type the following:
Sub showMessage()
MsgBox quot;Hello World!quot;
End Sub
2
3. 4. Click the Run button, , press [F5], or go to Run..Run Sub/UserForm to run the program
5. The message box pops up with the quot;Hello World!quot; greeting.
This is your first VBA program.
Task_1 : Using the above example as a benchmark create a VBA program that displays two separate message
boxes. One box should display the sentence “1st Box” while the second box will display the sentence “I did it”. Report
your results with a figure showing the boxes that you created and also show the VBA code that you created in your
program. (To see the recorded code you can follow the process described on Page 5 of this handout)
3
4. Recording Your First Macro
Recording a Macro
Microsoft Excel has a build-in macro recorder that translates your actions into VBA macro commands. After you
recorded the macro, you will be able to see the layout and syntax. Before you record or write a macro, plan the steps
and commands you want the macro to perform. Every actions that you take during the recording of the macro will be
recorded - including the correction that you made.
In this example, we will record a macro that sets the cell background color to light yellow. To record the macro,
follow the steps below:
1. Select Record New Macro ... under Tools...Macro
2. In the Record Macro dailog box, type quot;SetBackgroundColorquot; in the Macro Name textbox to set the macro
name. Leave all other option by default then click the Ok button. This will start the macro recording.
3. In the Background Color Panel, select the Ligth Yellow color box. This action will set the background of
the current cell (A1) in light yellow color.
4
5. 4. To stop the macro recording, click the Stop button (the navy blue rectangle) on the Macro Recorder
toolbar.
Now you have recorded a macro that set cell background to light yellow.
Task_2 : Create a Macro called “MyAverage” s=using the Macro Recording style. The macro will obtain the
average of 10 numbers located above the selected cell. The macro will also generate a scatter plot using the 10
numbers used before to calculate the corresponding average. For this macro you will use the relative reference style
as described during lecture. You also have to be able to run the macro using the Short Key sequence “Ctrl+p”. For
this task you only have to show/report the recorded code that was generated for the macro.
See the Recorded Syntax
The recorded macro is ready for use. Before we run the marco, let's look into the syntax.
1. To load the Visual Basic Editor, press [Alt] and [F11] at the same time. (Remember from our prior
lesson?) The Visual Basic Editor comes up.
5
6. 2. Expand the Modules folder in the Project Explorer by clicking on the plus (+) sign.
3. Double click the Module1 folder to see the sub routine (marco).
6
7. As the figure shows, the name of the sub routine is quot;SetBackgroundColorquot;. The color index for the light yellow is 36.
The background pattern is soild.
Run the Recorded Macro
In our prior example, we created the quot;Hello World!quot; marco. We ran the macro within the Visual Basic Editor. This
time we will run the recorded macro in the worksheet.
1. On any worksheet, select from D3 to E6.
2. Run the recorded macro by select Tools...Macro...Macros... or press [Alt] and [F8] at the same time.
7
8. 3. The Macro dailog box displayed. Since there is only one macro in the module, by default the only macro,
SetBackgroundColor is selected. Click the Run botton to run the macro.
4. Cells D3 to E6 now have light yellow background color.
8
9. Task_3 : Starting from any given cell (e.g., A30) input 10 new numbers in a column format (e.g., using cells
A:30:A40) and run the macro that you created in Task_2. After running the macro you should have two scatter plots
in your worksheet (i.e., one for the first set of data (Task_2) and another fort he 2nd set of data).
What happens when the selected cell (e.g., H15) has no data on top of it (e.g., no data on cells H5:H14). For this run
your macro (i.e., using Ctrl+p) to see what happens and report you findings (show your worksheet).
Modules and Procedures
Modules and Procedures and Their Scope
A module is a container for procedures as shown in our prior examples. A procedure is a unit of code enclosed
either between the Sub and End Sub statement or between the Function and End Function statements.
The following sub procedure (or sub routine) print the current date and time on cell C1:
Sub ShowTime()
Range(quot;C1quot;) = Now()
End Sub
The following function sum up two numbers:
Function sumNo(x, y)
sumNo = x + y
End Function
Procedures in Visual Basic can have either private or public scope. A procedure with private scope is only
accessible to the other procedures in the same module; a procedure with public scope is accessible to all procedures
in in every module in the workbook in which the procedure is declared, and in all workbooks that contain a reference
to that workbook. By default, procedures has public scope.
Here are examples of defining the scope for procedure.
Public Sub ShowTime()
Range(quot;C1quot;) = Now()
End Sub
Private Sub ShowTime()
Range(quot;C1quot;) = Now()
End Sub
Calling Sub Procedures and Function Procedures
There are two ways to call a sub procedure. The following example shows how a sub procedure can be called by
other sub procedures.
Sub z(a)
MsgBox a
End Sub
Sub x()
Call z(quot;ABCquot;)
End Sub
Sub y()
z quot;ABCquot;
End Sub
Sub z procedure takes an argument (a) and display the argument value (quot;ABCquot; in this example) in a message box.
Running either Sub x or Sub y will yield the same result because both sub-programs (i.e., subx() and suby(), send
the same arguments to subz().
The following example calls a function procedure from a sub procedure.
9
10. Sub ShowSum()
msgbox sumNo(3,5)
End Sub
Function sumNo(x, y)
sumNo = x + y
End Function
The ShowSum sub procedure calls the sumNo function and returns an quot;8quot; in a message box.
If there are procedures with duplicate names in different modules, you must need to include a module qualifier before
the procedure name when calling the procedure.
For example:
Module1.ShowSum
Passing Argument by Reference or by Value
If you pass an argument by reference when calling a procedure, the procedure access to the actual variable in
memory. As a result, the variable's value can be changed by the procedure. Passing by reference is the default in
VBA. If you do not explicitly specify to pass an argurment by value , VBA will pass it by reference. The following
two statements yield the same outcome.
Sub AddNo(ByRef x as integer)
Sub AddNo(x as integer)
Here is an example to show the by reference behavior. The sub procedure, TestPassing 1 calls AddNo1 by
reference and display quot;60quot; (50 + 10) on the message box.
Sub TestPassing1()
Dim y As Integer
y = 50
AddNo1 y
MsgBox y
End Sub
Sub AddNo1(ByRef x As Integer)
x = x + 10
End Sub
The following example shows the by value behavior. The sub procedure, TestPassing 2 calls AddNo2 by value and
display quot;50quot; on the message box.
Sub TestPassing2()
Dim y As Integer
y = 50
AddNo2 y
MsgBox y
End Sub
Sub AddNo2(ByVal x As Integer)
x = x + 10
End Sub
Task_4 : Using .the macro that you created in Task_2 modify the macro to display a massage box with the
massage “Plot Completed” after the plot has been created by running the macro. Fir this you will have a new line of
code at the end of the macro’s code (and before the End Sub command). Show the Massage box that is displayed
within your report (assignment) and show the code for the modified macro.
10
12. Department of Mechanical and Manufacturing Engineering
Schulich School of Engineering
University of Calgary
Computing Tools for Engineering Design (ENME 337 H(3-2))
Instructor:
Dr. Alejandro Ramirez-Serrano
Office: ME420 , Phone: 220-3632
E-mail: aramirez@enme.ucalgary.ca
“Visual Basic and Spreadsheet Programming Basics”
Excel VBA Basic Tutorial 2
This page contains the 2nd lesson on the Excel VBA Basic Tutorial series. It covers topics in the most used Excel
objects and collections. Beginners in VBA programming are encouraged to review the 1st lessons in this course
series if they had not already done so. This document contains information about the following topics.
Objects and Collections
Workbook and Worksheet Object
Range Object and Cells Property
Methods and Property
Assigning Object Variables and Using Named Argument
Microsoft Support site or the Excel VBA Help section on your computer contains comprehensive examples on most
the issues covered on this page. For more information, please refer to them.
Objects and Collections
Objects are the fundamental building blocks of Visual Basic. An object is a special type of variable that contains
both data and codes. A collection is a group of objects of the same class. The most used Excel objects in VBA
programming are Workbook, Worksheet, Sheet, and Range.
Workbooks is a collection of all Workbook objects. Worksheets is a collection of Worksheet objects.
The Workbook object represents a workbook, the Worksheet object represents a worksheet, the Sheet object
represents a worksheet or chartsheet, and the Range object represents a range of cells.
The following figure shows all the objects mentioned. The workbook (Excel file) is currently Book3.xls. The current
worksheet is Sheet1 as the Sheet Tab indicated. Two ranges are selected, range B2 and B7:B11.
12
13. Workbook and Worksheet Object
A workbook is the same as an Excel file. The Workbook collection contains all the workbooks that are currently
opened. Inside of a workbook there is at least one worksheet . In VBA, a worksheet can be referenced as followed:
Worksheets(quot;Sheet1quot;)
Worksheets(quot;Sheet1quot;) is the worksheet named quot;Sheet1.quot;
Another way to refer to a worksheet is to use number index like the following:
Worksheets(1)
The above refers to the first worksheet in the collection.
* Note that Worksheets(1) is not necessary the same sheet as Worksheets(quot;Sheet1quot;).
Sheets is a collection of worksheets and chart sheets (if present). A sheet can be indexed just like a worksheet
(similar to refereeing to elements in a matrix). Sheets(1) is the first sheet in the workbook.
To refer sheets (or other objects) with the same name, you have to qualify the object. For example:
Workbooks(quot;Book1quot;).Worksheets(quot;Sheet1quot;)
Workbooks(quot;Book2quot;).Worksheets(quot;Sheet1quot;)
If the object is not qualified, the active or the current object (for example workbook or worksheet) is used.
The sheet tab on the buttom the spreadsheet (worksheet) shows which sheet is active. As the figure below shows,
the active sheet is quot;Sheet1quot; (shown in bold font and white background).
13
14. You can change the color of the sheet tabs by right click the tab, choose Tab Color, then select the color for
the tab.
Task_5 : Open a workbook and name it “Task_5”. Then change the color of the three default sheets (i.e.,
Sheet1, Sheet2 and Sheet3) to green, red and blue, respectively. Subsequently, add a 4th worksheet to the
workbook names “Task_5”. For this use the same procedure that you used to change the color of the sheets
tabs, but now insert a new worksheet. Name the new worksheet (i.e., Sheet4) as “new”. Now your workbook
must have 4 worksheets (Sheet1, Sheet2, Sheet3 and new). Finally, rename Sheet1 as “First”, rename Sheet2
as “Test”, rename Sheet3 as “Yahooooo”. In your report show the workbook with all its sheets and renamed
sheets.!
The sub routine below shows the name of each sheet in the current opened workbook. You can use For
Each...Next loop to loop through the Worksheets collection. (To learn more about loops read Tutorial No 3
within this lab handout).
Sub ShowWorkSheets()
Dim mySheet As Worksheet
For Each mySheet In Worksheets
MsgBox mySheet.Name
Next mySheet
End Sub
Task_6 : Create a VBA program in Excel using the above code and run it! (This program can be created as a
macro) Observe what happens……. And report or show the results obtained after running the program.
Range Object and Cells Property
Range represents a cell, a row, a column, a selection of cells containing one or more contiguous blocks of cells, or a
3-D range. We will show you some examples on how Range object can be used.
The following example places text quot;ABquot; in range A1:B5, on Sheet2.
Worksheets(quot;Sheet2quot;).Range(quot;A1:B5quot;) = quot;ABquot;
14
15. Note that, Worksheets.Range(quot;A1quot;, quot;B5quot;) = quot;ABquot; will yield the same result as the above example, where the term
“A1” represents the 1st element forming the range and the term “B5” represents the last term within the range.
The following VBA code places the text quot;AAAquot; on cells A1, A3, and A5 on Sheet2.
Worksheets(quot;Sheet2quot;).Range(quot;A1, A3, A5quot;) = quot;AAAquot;
Task_7 : Using the workbook that you created in Task_5 write a VBA program similar to the above example
where you write the sentence “I did it!” instead of the letters” AAA”. The sentence “I did it!” should appear in the
range C2:E7 within Sheet3 or the sheet “Yahooooo” (since you renamed Sheet3 as Yahoooo in Task_5). Call your
VBA sub-routine “test”. Show the code that you created and the results within Sheet3. Note: Your code will be in a
subroutine called “test” as illustrated as follow:
Sub test()
Your code goes here!
End Sub
Range object has a Cells property. This property is used in every VBA projects on this website (very important ).
The Cells property takes one or two indexes as its parameters.
For example,
Cells(index) or Cells(row, column)
where row is the row index and column is the column index.
The following three statements are interchangable:
ActiveSheet.Range.Cells(1,1)
Range.Cells(1,1)
Cells(1,1)
The following returns the same outcome:
Range(quot;A1quot;) = 123 and Cells(1,1) = 123
The following puts quot;XYZquot; on Cells(1,12) or Range(quot;L1quot;) assume cell A1 is the current cell:
Cells(12) = quot;XYZquot;
15
16. The following code puts quot;XYZquot; on cell C3:
Range(quot;B1:F5quot;).cells(12) = quot;XYZquot;
Why ???? (see Task_8)
* The small gray number on each of the cells is just for reference purpose only. They are used to show how the cells
are indexed within the range.
Task_8 : Explain why the command Range(“B1:F5”).cell(12)=XYZ places “XYZ” in cell C3? Change the range
and see what happens. For example, use Range(“A1:G15”).cell(12)=”XYZ”. Which cell gets the “XYZ” ?
Here is a sub routine that prints the corresponding row and column index from A1 to E5.
Sub CellsExample()
For i = 1 To 5
For j = 1 To 5
Cells(i, j) = quot;Row quot; & i & quot; Col quot; & j
Next j
Next i
End Sub
** For information about “For” loops read Tutorial No 3 within this lab handout.
Range object has an Offset property that can be very handy when one wants to move the active cell around. The
following examples demostrate how the Offset property can be implemented (assume the current cell before the
move is E5):
ActiveCell.Offset(1,0) = 1 This command places a quot;1quot; one row under E5 (on E6)
16
17. ActiveCell.Offset(0,1) = 1 This command places a quot;1quot; one column to the right of E5 (on F5)
ActiveCell.Offset(0,-3) = 1 This command places a quot;1quot; three columns to the left of E5 (on B5)
Task_9 : Open a new Excel file and write a VBA program that writes the world “Yes” on top, on the
bottom and to the left and right side of the active cell! For this you can use the previous program located in
the previous page as a base program that needs to be modified. For this you might need to use your
knowledge about IF statements (described in Tutorial 3 within this lab handout).
After you complete your program select cell D3 as your active cell and run your program. Now select A12 as
you active cell and run your program. Explain what happens when you select cell A12 as your active cell.
“Try your best”!
Using the macro created in lecture to convert ºF to ºC you can start your program with the following
commands:
Sub write()
ActiveCell. Select() ‘This part selects your current cell as the active cell
Your code goes here! To display your message here you will use the offset to define what you want
End Sub
Methods and Properties
Each object contains its own methods and properties.
A Property represents a built-in or user-defined characteristic of the object. A method is an action that you
perform with an object. Below are examples of a method and a property for the Workbook Object:
17
18. Workbooks.Close
Close method close the active workbook
Workbooks.Count
Count property returns the number of workbooks that are currently opened
Some objects have default properties. For example, Range's default property is Value.
The following yields the same outcome.
Range(quot;A1quot;) = 1 and Range(quot;A1quot;).Value = 1
Here are examples on how to set and to get a Range property value:
The following sets the value of range A1 or Cells(1,1) as quot;2005quot;. It actually prints quot;2005quot; on A1.
Range(quot;A1quot;).Value = 2005
The following gets the value from range A1 or Cells(1,1).
X = Range(quot;A1quot;).Value
Method can be used with or without argument(s). The following two examples demostrate this behavior.
Methods That Take No Arguments:
Worksheets(quot;Sheetquot;).Column(quot;A:Bquot;).AutoFit
Methods That Take Arguments:
Worksheets(quot;Sheet1quot;).Range(quot;A1:A10quot;).Sort _
Worksheets(quot;Sheet1quot;).Range(quot;A1quot;)
Worksheets(quot;Sheet1quot;).Range(quot;A1quot;) is the Key (or column) to sort by.
Assigning Object Variables and Using Named Argument
Sometime a method takes more than one argument. For example, the Open method for the Workbook
object, takes 12 arguments. To open a workbook with password protection, you would need to write the following
code:
Workbooks.Open quot;Book1.xlsquot;, , , ,quot;pswdquot;
Since this method takes so many arguments, it is easy to misplace the password argument. To
overcome this potential problem, one can use named arguments like the following example:
Workbook.Open fileName:= quot;Book1.xlsquot;, password:= quot;pswdquot;
You can also assign an object to an object variable using the Set Statement.
For example:
Dim myRange as Range
Set myRange = Range(quot;A1:A10quot;)
End of Tutorial No. 2
18
19. Department of Mechanical and Manufacturing Engineering
Schulich School of Engineering
University of Calgary
Computing Tools for Engineering Design (ENME 337 H(3-2))
Instructor:
Dr. Alejandro Ramirez-Serrano
Office: ME420 , Phone: 220-3632
E-mail: aramirez@enme.ucalgary.ca
“Visual Basic and Spreadsheet Programming Basics”
Excel VBA Basic Tutorial 3
This page contains the 3rd lesson on the Excel VBA Basic Tutorial series. It covers topics in creating and managing
arrays and understanding the VBA decision and loop structures. Beginners in VBA programming are encouraged to
go through the prior lessons in this series if they had not already done so. This document contains information about
the following topics.
IMPORTANT NOTE : This tutorial contains 4 tasks (Task_10, Task_11, Task_12 and Task_13). Al
these tasks are optional and you can work on these tasks on your spare time. That is, these tasks
are not required to be included in your lab report as part of Assignment No 2. However, the topics
included in this tutorial will be included in the Excel ’ s mid term exam to be held on Friday
September 30, 2005 during lecture time .
• Creating and Managing Array s
Declare an Array With Dim Statement
Resize an Array With Redim Statement
Manage Dynamic Array
Create Multi-Dimensional Array
Find The Size of an Array
• Decision Structures - IF and Select Case
IF ... Then
IF ... Then ... Else
IF ... Then ... ElseIf
Select Case
• Loop Structures
For ... Next
For ... Next Loop With Step
Do While ... Loop
Do Until ... Loop
Do ... Loop While
Do ... Loop Until
Microsoft Support site or the Excel VBA Help section on your computer contains comprehensive examples on most
the issues covered on this page. For more information, please refer to them.
Creating and Managing Array
19
20. Declaring an Array With Dim Statement
An array is a set of sequentially indexed elements having the same intrinsic data type. Each element of an array has
a unique identifying index number. Changes made to one element of an array don't affect the other elements.
Before assigning values to an array, the array needs to be created. You can declare the array by using the Dim
statement.
For example, to declare a one-dimensional array with 5 elements, type the following:
Dim Arr(4)
The element’s index of the array starts from 0 unless Option Base 1 is specified in the public area (area outside of
the sub procedure). If Option Base 1 is specified, the index will start from 1.
The following example assigns values to the array and displays all values in a message box :
Option Base 1
Sub assignArray( )
Dim Arr(5)
Arr(1) = “Jan”
Arr(2) = “Feb”
Arr(3) = “Mar”
Arr(4) = “Apr”
Arr(5) = “May”
Msgbox Arr(1) & quot;-quot; & Arr(2) & quot;-quot; & Arr(3) & quot;-quot; & Arr(4) & quot;-quot; & Arr(5)
End Sub
* The number inside the array, i.e. Arr(1), is the index. One (1) is the index of the first element in the array.
Task_10 (optional) : Based on the above program write a subroutine (program) to create a one-dimensional
array named “operations”. The “operations” array should contain 4 elements where each element in the array will
hold the number resulting from the basic operations: +. -, *, and / performed over the numbers within cells A1 and B1.
When you run your program the result from the operations must be displayed in cells A5, B5, C5 and D5 as
illustrated in the figure below.
20
21. Resize an Array With Redim Statement
The ReDim statement is used to size or resize a dynamic array that has already been formally declared.
For example, if you have already declared an array with an element value of 5 and decided to change the number of
the element to 6, you can do the following to resize the array:
Redim Arr(6)
We incorporate it into our last example:
Option Base 1
Sub assignArray( )
'Dim Arr(5)
Redim Arr(6)
Arr(1) = “Jan”
Arr(2) = “Feb”
Arr(3) = “Mar”
Arr(4) = “Apr”
Arr(5) = “May”
Arr(6) = “Jun”
Msgbox Arr(1) & quot;-quot; & Arr(2) & quot;-quot; & Arr(3) & quot;-quot; & Arr(4) & quot;-quot; & Arr(5)
End Sub
Note that the Dim Arr(5) statement is commoned out, because leaving this original statement in the sub will cause a
compilation error.
Manage Dynamic Array
A word of caution in using the Redim Statement to resize an array - resize the array can erase the elements in it. In
the following example, all the values assigned prior to resize the array are erased. Only the value assigned to the
array after resize remains.
21
22. Option Base 1
Sub assignArray( )
Redim Arr(5)
Arr(1) = “Jan”
Arr(2) = “Feb”
Arr(3) = “Mar”
Arr(4) = “Apr”
Arr(5) = “May”
Redim Arr(6)
Arr(6) = “Jun”
Msgbox Arr(1) & quot;-quot; & Arr(2) & quot;-quot; & Arr(3) & quot;-quot; & Arr(4) & quot;-quot; & Arr(5) & quot;-quot; & Arr(6)
End Sub
By replacing the Redim Arr(6) with Redim Preserve Arr(6), all values will remain. For example:
Option Base 1
Sub assignArray( )
Redim Arr(5)
Arr(1) = “Jan”
Arr(2) = “Feb”
Arr(3) = “Mar”
Arr(4) = “Apr”
Arr(5) = “May”
Redim Preserve Arr(6)
Arr(6) = “Jun”
Msgbox Arr(1) & quot;-quot; & Arr(2) & quot;-quot; & Arr(3) & quot;-quot; & Arr(4) & quot;-quot; & Arr(5) & quot;-quot; & Arr(6)
End Sub
Task_11 (optional) : Open Excel and create a VB program using the above code and run it! Now modify the
created program to display the content of the message window of the above code in cells A1 to A6. That is, when
running the modified code each month should be displayed in cells Ai where i = 1, 2, 3, 4, 5, 6. For example: “Jan”
should appear in cell A1, “Feb” should appear in Cell A2, etc.
22
23. Create Multi- Dimensional Array
An array can also store multiple dimensional data. To simplify our tutorial, example on a two-dimensional array is
used. Assume you have data of a local store's yearly sale in the following table and you want to store the data in a
two-dimensional array:
Year 2003 Year 2004
CD Sale 1,000 1,500
DVD Sale 1,200 2,000
First we create the array as follow:
Dim Arr(2,2)
Then we assign the values into the array. We treat the first dimension as the year and the second dimension as the
product sale:
arr(1,1) = 1000
arr(1,2) = 1200
arr(2,1) = 1500
arr(2,2) = 2000
We now display the values of the array with a message box:
Msgbox quot;Sale of CD in 2003 is quot; & arr(1,1) & vbCrLf & quot;Sale of CD in 2004 is quot; _
& arr(2,1) & vbCrLf & quot;Sale of DVD in 2003 is quot; & arr(1,2) & vbCrLf _
& quot;Sale of DVD in 2004 is quot; & arr(2,2)
The complete precedure is as followed:
Option Base 1
Sub multDimArray( )
Dim Arr(2,2)
arr(1,1) = 1000
arr(1,2) = 1200
arr(2,1) = 1500
arr(2,2) = 2000
Msgbox quot;Sale of CD in 2003 is quot; & arr(1,1) & vbCrLf & quot;Sale of CD in 2004 is quot; _
& arr(2,1) & vbCrLf & quot;Sale of DVD in 2003 is quot; & arr(1,2) & vbCrLf _
& quot;Sale of DVD in 2004 is quot; & arr(2,2)
End Sub
Task_12 (optional) : a) Open Excel and create and run the above program. Observe the result. b) Modify the
program by erasing some of the “vbCRLf” commands and run the program. c) Repeat part “b” of this task modifying
the program in different ways (i.e., erasing or adding the command vbCrLf). Explain what does the command
“vbCrLf” stands for and its use. d) Repeat tasks “b” and “c” of this exercise for the command”_” (i.e., underscore) at
the end of the first and second lines. Explain what does the underscore stands for.
23
24. Find The Size of an Array
The largest available subscript for the indicated dimension of an array can be obtained by using the Ubound
function. In our one-dimensional array example, Ubound(arr) is 5.
In our two-dimensional array example above, there are two upper bound figures - both are 2.
UBound returns the following values for an array with these dimensions*:
Dim A(1 To 100, 0 To 3, -3 To 4)
Statement Return Value
UBound(A, 1) 100
UBound(A, 2) 3
UBound(A, 3) 4
* Example taken from Excel VBA Help section.
The UBound function is used with the LBound function to determine the size of an array. Use the LBound function
to find the lower limit of an array dimension.
Statement Return Value
LBound(A, 1) 1
LBound(A, 2) 0
LBound(A, 3) -3
To get the size of an array, use the following formula:
UBound(Arr) - LBound(Arr) + 1
For example:
Ubound(A,1) - LBound(A,1) + 1
= 100 - 1 + 1
= 100
Ubound(A,2) - LBound(A,2) + 1
= 3-0+1
=4
Ubound(A,3) - LBound(A,3) + 1
= 4 - (-3) + 1
=8
For more information on arrays you can check the following web site:
http://support.microsoft.com/default.aspx?scid=%2Fsupport%2Fexcel%2Fcontent
%2Fvba101%2Fvbc5-3.asp&FR=0
Decision Structures - IF and Select Case
IF ... Then Statement
The IF ... Then is a single condition and run a single statement or a block of statement.
Example, the following statement set variable Status to quot;Adultquot; if the statement is true:
If Age >= 18 Then Status = quot;Adultquot;
You can also use multiple-line block in the If statement as followed:
If Ago >= 18 Then
Status = quot;Adultquot;
Vote = quot;Yesquot;
End If
Note that in the multiple-line block case, End If statement is needed, where the single-line case does not.
24
25. IF ... Then ... Else
The If ... Then ... Else statement is used to define two blocks of conditions - true and false.
Example:
If Age >=22 Then
Drink = quot;Yesquot;
Else
Drink = quot;Noquot;
End If
Again, note that End If statement is needed in this case as well since there is more than one
block of statements.
IF ... Then ... ElseIf
The IF ... Then ... ElseIf is used to test additional conditions without using new If ... Then statements.
For Example:
If Age >= 18 and Age < 22 Then
Msgbox quot;You can votequot;
ElseIf Age >=22 and Age < 62 Then
Msgbox quot;You can drink and votequot;
ElseIf Age >=62 Then
Msgbox quot;You are eligible to apply for Social Security Benefitquot;
Else
Msgbox quot;You cannot drink or votequot;
End If
Note that the last condition under Else is, implicitly, Age < 18.
Select Case
Select Case statement is an alternative to the ElseIf statement. This method is more efficient and readable in
coding the If ... Then ... ElseIf statement.
Example:
Select Case Grade
Case Is >= 90
LetterGrade = quot;Aquot;
Case Is >= 80
LetterGrade = quot;Bquot;
Case Is >= 70
LetterGrade = quot;Cquot;
Case Is >= 60
LetterGrade = quot;Dquot;
Case Else
LetterGrade = quot;Sorryquot;
End Select
Loop Structures
For ... Next
Use For ... Next loop if the number of loops is already defined and known. A For ... Next loop uses a counter
variable that increases or decreases in value during each iteration of the loop. This loop structure is being used the
most for our examples on this Lab session.
Here is an example of the For ... Next loop:
25
26. For i = 1 to 10
Cells(i, 1) = i
Next i
In this example, i is the counter variable from 1 to 10. The looping process will send value to the first column of the
active sheet and print i (which is 1 to 10) to row 1 to 10 of that column.
Note that the counter variable, by default, increases by an increment of 1.
For ... Next Loop With Step
You can use the Step Keyword to sepcify a different increment for the counter variable.
For example:
For i = 1 to 10 Step 2
Cells(i, 1) = i
Next i
This looping process will print values with an increment of 2 on row 1, 3, 5, 7 and 9 on column one.
You can also have decrement in the loop by assign a negative value afte the Step keyword.
For example:
For i = 10 to 1 Step -2
Cells(i, 1) = i
Next i
This looping process will print values with an increment of -2 starts from 10 on row 10, 8, 6, 4 and 2 on column one.
26
27. Do While ... Loop
You can use the Do While ... Loop to test a condition at the start of the loop. It will run the loop as long as the
condition is ture and stops when the condition becomes false. For Example:
i=1
Do While i =< 10
Cells(i, 1) = i
i=i+1
Loop
This looping process yields the same result as in the For ... Next structures example.
One thing to be caution is that sometimes the loop might be a infinite loop. And it happens when the condition never
beomes false. In such case, you can stop the loop by press [ESC] or [CTRL] + [BREAK] .
Do Until ... Loop
You can test the condition at the beginning of the loop and then run the loop until the test condition becomes true.
Example:
i=1
Do Until i = 11
Cells(i, 1) = i
i=i+1
Loop
This looping process yields the same result as in the For ... Next structures example.
Do ... Loop While
When you want to make sure that the loop will run at least once, you can put the test at the end of loop. The loop will
stop when the condition becomes false.
For Example:
i=1
Do
Cells(i, 1) = i
i =i+1
Loop While i < 11
This looping process yields the same result as in the For ... Next structures example.
Task_13 (optional) : Compare the Do …Loop While loop structure with the Do ….While Loop. For this run
similar programs using these two loop structures (e.g., use the above code and the code used in the Do …. While
loop section). What are the differences between these two loop structures? Modify your programs and see the
results from where you will be able to determine the answers to the above question.
27
28. Do ... Loop Until
This loop structure, like the Do ... Loop While , makes sure that the loop will run at least once, you can put the test
at the end of loop. The loop will stop when the condition becomes true. (compare this loop structure to the Do ...
Until Loop.)
For Example:
i=1
Do
Cells(i, 1) = i
i =i+1
Loop Until i = 11
This looping process yields the same result as in the For ... Next structures example.
End of Tutorial No. 3
28