100% found this document useful (3 votes)
9 views

Excel VBA Step By Step Guide to Learning Excel Programming Language for Beginners 1st Edition by Jason Jay ISBN 1976198127 9781976198120 pdf download

The document is a step-by-step guide for beginners to learn Excel VBA programming, authored by Jason Jay. It covers essential topics such as accessing the Developer tab, creating and running macros, and understanding VBA fundamentals. The guide includes practical examples, quizzes, and projects to help users effectively learn and apply VBA in Microsoft Excel.

Uploaded by

saffoyuhasl9
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
9 views

Excel VBA Step By Step Guide to Learning Excel Programming Language for Beginners 1st Edition by Jason Jay ISBN 1976198127 9781976198120 pdf download

The document is a step-by-step guide for beginners to learn Excel VBA programming, authored by Jason Jay. It covers essential topics such as accessing the Developer tab, creating and running macros, and understanding VBA fundamentals. The guide includes practical examples, quizzes, and projects to help users effectively learn and apply VBA in Microsoft Excel.

Uploaded by

saffoyuhasl9
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 75

Excel VBA Step By Step Guide to Learning Excel

Programming Language for Beginners 1st Edition


by Jason Jay ISBN 1976198127 9781976198120 pdf
download
https://ebookball.com/product/excel-vba-step-by-step-guide-to-
learning-excel-programming-language-for-beginners-1st-edition-by-
jason-jay-isbn-1976198127-9781976198120-15878/

Explore and download more ebooks or textbooks


at ebookball.com
Get Your Digital Files Instantly: PDF, ePub, MOBI and More
Quick Digital Downloads: PDF, ePub, MOBI and Other Formats

Java Easy Java Programming for Beginners Step By Step Guide to


Learning Java 1st Edition by Felix Alvaro ISBN 1539509362
9781539509363

https://ebookball.com/product/java-easy-java-programming-for-
beginners-step-by-step-guide-to-learning-java-1st-edition-by-
felix-alvaro-isbn-1539509362-9781539509363-15874/

Java programming A beginners guide to java Step by Step 1st Edition


by Troy Dimes 1507562942 978-1507562949

https://ebookball.com/product/java-programming-a-beginners-guide-
to-java-step-by-step-1st-edition-by-troy-
dimes-1507562942-978-1507562949-17382/

Microsoft Excel 2016 Step by Step 1st Edition by Curtis Frye ISBN
0735697469 9780735697461

https://ebookball.com/product/microsoft-excel-2016-step-by-
step-1st-edition-by-curtis-frye-
isbn-0735697469-9780735697461-16138/

PYTHON'S COMPANION A STEP BY STEP GUIDE FOR BEGINNERS TO STAR


TODAY 1st edition by Joe Thompson ISBN 0123456789 978-0123456789

https://ebookball.com/product/python-s-companion-a-step-by-step-
guide-for-beginners-to-start-coding-today-1st-edition-by-joe-
thompson-isbn-0123456789-978-0123456789-16686/
Excel 2016 Power Programming With VBA 1st Edition by Michael
Alexander, Richard Kusleika ISBN 1119067723 9781119067726

https://ebookball.com/product/excel-2016-power-programming-with-
vba-1st-edition-by-michael-alexander-richard-kusleika-
isbn-1119067723-9781119067726-15876/

Research Methodology A Step By Step Guide for Beginners 3rd Edition by


Ranjit Kumar 1849203016 978-1849203012

https://ebookball.com/product/research-methodology-a-step-by-
step-guide-for-beginners-3rd-edition-by-ranjit-
kumar-1849203016-978-1849203012-17356/

Machine Learning Step by Step Guide To Implement Machine Learning


Algorithms with Python 1st Edition by Rudolph Russell ISBN
9781719528405

https://ebookball.com/product/machine-learning-step-by-step-
guide-to-implement-machine-learning-algorithms-with-python-1st-
edition-by-rudolph-russell-isbn-9781719528405-16086/

Assembly Language Step by Step Programming with DOS and Linux 2nd
Edition by Jeff Duntemann ISBN 0471375233 9780471375234

https://ebookball.com/product/assembly-language-step-by-step-
programming-with-dos-and-linux-2nd-edition-by-jeff-duntemann-
isbn-0471375233-9780471375234-12520/

(Ebook PDF) RESEARCH METHODOLOGY a step by step guide for beginners


1st edition by Ranjit Kumar 1849203016‎ 978-1849203012 full
chapters

https://ebookball.com/product/ebook-pdf-research-methodology-a-
step-by-step-guide-for-beginners-1st-edition-by-ranjit-
kumar-1849203016aeurz-978-1849203012-full-chapters-23028/
EXCEL VBA

Step-By-Step Guide To Learning Excel


Programming Language For Beginners

Jason Jay
© Copyright 2017 by Jason Jay - All rights reserved.

If you would like to share this book with another person, please purchase an
additional copy for each recipient. Thank you for respecting the hard work of
this author. Otherwise, the transmission, duplication or reproduction of any of

the following work including specific information will be considered an


illegal act irrespective of if it is done electronically or in print. This extends
to creating a secondary or tertiary copy of the work or a recorded copy and is
only allowed with express written consent from the Publisher. All additional
right reserved.
TABLE OF CONTENT
EXCEL VBA 1
Introduction 5
CHAPTER 1 7
VBA Developer TAB 7
Accesing to the Developer TAB 7
Quiz 1 8
CHAPTER 2 9
Macros 9
Creating a Macro 9
Relative References 11
Running the Macro 12
Saving a Macro-Enabled Workbook 12
Quiz 2 14
CHAPTER 3 16
Starting with VBA 16
What if I need to fill the cells up to 100? 19
Insert Form Button 21
Simple things a Macro can’t do. 22
Insert ActiveX Button 22
Variables, Do and Loop. 23
What is the advantage of declaring variables as byte, integer or any other? 31
APPs Performance 35
MSGBOX 39
If and Select Case 40
Quiz 3 43
CHAPTER 4 45
Project: Creating a Simple Calculator using ActiveX 45
What is a Module? 45
How to create a Module 46
Adding Letters? 58
Quiz 4 59
CHAPTER 5 60
Project: Calculator using Forms 60
Review 60
FORMS 61
Commmand Buttons code 65
Excel Formulas on VBA 74
Combining VBA and a Spreadsheet 75
Starting with Declarations: 78
Open and Close declarations: Displaying a form without looking any spreadsheet 81
Macro Security 87
Comments 89
The whole code for Calculator Project 94
Command Buttons Order 101
Adding Password to VBA Code. 102
Quiz 5 104
Interacting with other Applications. 105
Opening other apps from Excel 105
Sending an Outlook e-mail from Excel: 108
Exercises Solutions: 111
Answers Chapter 1 111
Answers Chapter 2 112
Answers Chapter 3 113
Answers Chapter 4 114
Answers Chapter 5 115
Introduction

If you already know how to use Microsoft Excel but there’re a few
things you can’t do, it is time to learn the strongest functionality it has, Visual
Basic for Applications (VBA).
Visual Basic for Applications is a programming language incorporated
in Microsoft Excel, Access, PowerPoint and even Word, which let you do all
things you already know about them and much more. For example, you want
that every time you open a specific Microsoft Word file it writes
automatically the current date two lines below where you left last time. Or
maybe you want a whole spreadsheet of Excel without formulas on it and still
applying them as if they were there. How would you do that? All these things
and much more are done with Visual Basic for Applications for Microsoft
Office.
Look at the example below:

It looks like a program made for analysis, and it does. Guess what
program it is? Probably you are thinking it is not any Microsoft Office
program, but let me tell you that it was made with Microsoft Excel, how
would you do something like that without programming? There’s no way!
You’ll learn much more than that and will be able to create your own
programs using Visual Basic for Applications (VBA).
If you need a very specific program for your business analysis,
something for personal use, or even just for having fun, you need Visual
Basic for Applications now!
CHAPTER 1
VBA Developer TAB

Every programming language has similarities between their


fundamentals. The functions IF, Then, Loop, Close, Open, are just some of
them. We’ll learn the basic ones first; it will be necessary to understand how
VBA works.

We’ll use Microsoft Excel 365 for this instructions and examples, however,
from Microsoft Excel 2007 onwards it will work the same.
Accesing to the Developer TAB

Microsoft Excel doesn’t show the Developer TAB by default. It only has
File, Home, Insert, etc. But there’s no one called Developer. To access to this
TAB there are different options, but we’ll show the easiest one.
1. Right click to the Ribbon (any part inside the red box, except the
buttons).

2. Select Customize the Ribbon

3. Enable the Developer checkbox and click the OK button.


4. You should see the Developer TAB available now.

Quiz 1

1. How you Access the Developer TAB?


a) It is available by default in Excel.
b) Right click on the Ribbon, Customize the Ribbon, enable the
Checkbox for Developer and Accept.
c) Go to file, Options, Advanced and Enable the Developer TAB.
CHAPTER 2
Macros

Creating a Macro
You’ll see a few options available in the Developer TAB, by now we’ll start
to use the Record Macro button.
A Macro is an automated sequence which will apply every time you play it.
Let’s see a practical example of it:
Imagine that in your job you do the same process every morning. It takes
some valuable time and even you’re getting bored of that.
The process is the following:
a) You receive a Microsoft Excel file from your boss with some data
and you need to write the date using Year, Month and Day in different
columns.
You do this because it is the format your job needs and you’ve been adding
the same values every day for a few years.
In this case an semi-automated process would be helpful. Excel gives that
option to all of us with Macros. A Macro is a semi-automated process which
let you run a specific task using a shortcut.
To create a Macro, follow the sequence below:
a) Click the Record a Macro Button.
b) Write a name for your Macro. (Needed)
c) A shortkey which every time you press will Run the Macro. Be
careful, don’t add Ctrl + C or Ctrl + v, otherwise it won’t copy or paste
anymore, but run the Macro. In case you want a more specific shortcut,
hold the shift key as you press a letter. For example, ctrl + shift + c. To
make it work, don’t press ctrl as you add a short cut. (Optional)
d) Store Macro in: Personal workbook: Will be available for all the
files you open with Excel on that computer; New Workbook will be
available for a new file only. This workbook, will apply only to the
current open file. (Needed to choose one)
e) Write a description about what that Macro does. (Optional)
f) Click Ok.

g) Start doing everything you always do, which would be adding the
current date in this case.
h) Once you finish, go back to the Record Macro Button, which now is
called Stop Recording. Press it and now should be saved.
This would be a very simple Macro, it only adds the current date, but what
would you think if you also need to import data from a web page which is
updated every hour, and need to classify it using a few charts, and you do the
same process several times a day. No doubt, a good Macro would be useful.
The process to get it any Macro, is the same we’ve followed. There’s only an
important thing to consider when creating one, it is to choose between using
Relative References or not.

Relative References
The Relative References button is just below the Record a Macro Button.
Once you click on it, it remains active until you click on it again. It is used to
record macros in which the process should be applied to different ranges
instead of one already set.
Its functionality is very useful. A macro recorded without relative references
will always repeat the process on the same cells used when recorded. But if
you use relative references, the macro will run from the active cell. Using the
example above, what If you need the dates written on cells F4:H4 instead of
B2:D2? The only thing you should do is to select F4 and run the Macro. Or
select any cell you need and run it. But you need to record the Macro using
Relative References, and then select the cell and run it, otherwise it wouldn’t
work.

Running the Macro


There are a bunch of ways to run a Macro. Let’s see the first: Run this one by
clicking on the Macros Button, then click on it to run it.
Maybe it is not as practical as we expected, however, we’ll add more
functionality and make it easier to run in the next step.

Saving a Macro-Enabled Workbook


Once you have added some Macros to your worksheet and try to save it
you’ll get a notification like the following:

This might be a little tricky, because most people would attempt saving the
file without reading this notification:
The following features cannot be saved in macro-free workbooks:
°VBA project
To save a file with these features, click No, and then choose a macro-enabled
file in the File Type list.
To continue saving as a macro-free workbook, click Yes.
Most people would just click Yes, and according to this message they
wouldn’t save the file with their Macros, but as Macro free. It would make
you lose all your Macro work.
To save the Macro, just click No to the message above, then select save as
Excel Macro-Enabled Workbook.
Click on Save, and it is done!
Once you open it again, you should see a message saying Macros have been
disabled, and a Button saying Enable Macros. Click on it and won’t have
further problems. If you don’t click on it, you won’t be able to work with
VBA, at least you enable them on Macro Security in the Developer TAB, or
follow the steps on Chapter 5: Macro Security.

Quiz 2
1. What is a Macro?
a) It is an Excel Formula
b) It is a shortcut which runs a recorded process.
c) It is a built-in process included in Excel.

2. How to create a Macro?


a) Clicking on the Visual Basic Button
b) Clicking on the Macros Button
c) Clicking on the Record Macro Button

3. What is Relative References for?


a) It is to Record a Macro without set specific cells.
b) It is to Record a Macro with specific cells.
c) Without it a Macro isn’t editable.

4. How to Run a Macro?


a) Clicking on the Macro Button
b) Clicking on the Record Macro Button
c) Clicking on the Relative References Button

5. How to save a workbook with Macros?


a) Just save the file normally, the Macros will be saved.
b) You’ll get a notification, in which we should be denied and then
select save as Macro-Enabled Workbook.
c) You’ll get a notification, in which we will be notified that we are
saving a Macro-enabled workbook, then just accept to save.
CHAPTER 3
Starting with VBA

Macros are fundamental to be introduced to VBA.


Let’s see why by following the process:
1.-Create a new Macro without relative references.
2.-In the process select the cell A1, write a number 1, and press enter.
3.-Stop Recording.

Next to the Record Macro button, there’s another one called Visual Basic.
Click on it and you’ll see a code like this:

Range("A1").Select
ActiveCell.FormulaR1C1 = "1"
Range("A2").Select

Congrats, you have some Visual Basic Code now. It means a few orders:
Select Cell A1
Write the number 1
Select Cell A2

It is exactly what we did. But now, we’ll edit the code so that the Macro does
something else.
If we see, there’s a pattern, which is: select, write, select. So, we could
continue the pattern by adding a few more things directly, like this:

Range("A1").Select
ActiveCell.FormulaR1C1 = "1"
Range("A2").Select
ActiveCell.FormulaR1C1 = "2"
Range("A3").Select
ActiveCell.FormulaR1C1 = "3"
Range("A4").Select

Now that you added this, run the macro, but now you’ll see a second way to
run it. Press the green button above the code. Once you click on it go to the
Excel Spreadsheet by clicking on the Excel symbol. You’ll see that the cells
A1:A3 are filled with the numbers we wrote and the Cell A4 is selected.
It may look very complex, and it is like that because humans use to do things
that machines wouldn’t. I needed to select cell A1, A2, A3 and son on. But
does Excel really need to select it to write a simple number?
Let’s try it by adding the following code:

Range("A1") = 1
Range("A2") = 2
Range("A3") = 3

That’s it! Excel can skip steps humans can’t. So, it makes it much more faster
and easy to accomplish its work.

What if I need to fill the cells up to 100?


Now, I think that if I need to follow this pattern until A100 is going to be
hard. What should I do?
Let’s add this:

Range("A1:A100") = 1

Oops! It adds a number 1 to all cells from A1 to A100. Let’s try another
thing:

Range("A1:A100") = 1 + 1

It adds a number two instead. So, How do I tell Excel that I want it to fill
cells in sequence?

There are several ways. One is to record a Macro and during the process add
a number 1 to the cell A1, then hold right click on the small square and scroll
down until you select A100. Select fill series. Go to Visual Basic and you’ll
see a code like this:

Range("A1").Select
ActiveCell.FormulaR1C1 = "1"
Selection.AutoFill Destination:=Range("A1:A100"),
Type:=xlFillSeries
Range("A1:A100").Select
It works! I think we already have a great idea about how to get the VBA code
we want. Record a Macro, and there it is. However, there’re a lot of functions
that Macros can’t offer. For example, fill up cells in sequence according to
the number written in cell B2, and once it changes fill up the sequence again
according to that number. So, if there’s a number 1 it will be filled one by
one, if I change it to five, it’ll go five by five and so on. How are you going
to record that in a Macro? What if it is not just filling up a sequence, but a
Financial matter, working with real numbers and you need to solve a problem
like this fast?
Recording a Macro isn’t enough always, but in most cases, it helps.
Visual Basic Application (VBA) is a programming language, but it is not
necessary to know VBA code or computer programming if the Macro
Recorder does what you want.
You should know that when you record a Macro it records even your
mistakes, and it will repeat them when you run it. If you want to solve a
problem like this you have two options:
1. Record the Macro again.
2. Edit the VBA code.
Remember that recording a good Macro or writing a good VBA code,
will make Excel to run smoothly. Otherwise, you can expect a not
responding message until it finishes or maybe it even could stop
working.
We’ll focus on things you can’t do using only recorded macros. So, you can
learn how powerful Visual Basic for Applications is in Microsoft Excel.

Insert Form Button


We have some Macros recorded now. But we see that to run them it is not
that handy, so what if we add a button, and every time we press it on the
macro runs?
To do that, click on the insert button in the Developer TAB. You’ll see it
displays two boxes, called form controls and ActiveX Controls. Let’s select
the Form Control Button, then wherever you want on the spreadsheet hold
and drag to create the size of the button. Once you stop holding you’ll see a
new window in which you will be able to choose the Macro you want the
Button to run. Select it and it’s done.
If you want to change the name of the button just click on it twice slowly or
right click, edit text. To move the position of the button, just right click, and
then hold and drag with the left click.

Easy, don’t you think?

Simple things a Macro can’t do.


Insert ActiveX Button
Let’s add an ActiveX Button. To do this in the Developer TAB click on
Insert, and then select ActiveX Button. Hold and drag to create the button in
the spreadsheet. This kind of button are very different than Form Buttons,
because these ones work directly with VBA.
Let’s add some functionality which can’t be done using Macros only. We
want that button to create a sequence of numbers according to the value
inserted in cell B2. I mean, if I add number 1 then I’ll see a pattern going one
by one. If I write 5, then it will go five by five, and so on, from A1 to A100.
This is a great opportunity to explain Variables.

Variables, Do and Loop.


A variable is an algebraic term, which is usually represented by a letter and
its value varies, for example, x + y = 10, in this equation there are two
variables, X and Y. They can vary to equal 10. If X = 5 and Y = 5 then
x+y=10 , and it is also correct if X= 8 and Y=2, because X+Y= 8+2 = 10.
Etc.

In VBA we declare variables too. In this case we’ll add some functionality to
the ActiveX Button we added in the previous step.
First, we’ll need to choose the correct numeric variable.

These are the most types of variables, check them out and see their storage
size and range by now:

Data type Storage Range


size
Byte 1 byte 0 to 255

Boolean 2 bytes True or False

Integer 2 bytes -32,768 to 32,767

Long 4 bytes -2,147,483,648 to 2,147,483,647


(long integer)
Single 4 bytes -3.402823E38 to -1.401298E-45 for negative
(single- values; 1.401298E-45 to 3.402823E38 for
precision positive values
floating-point)
Double 8 bytes -1.79769313486231E308 to
(double- -4.94065645841247E-324 for negative values;
precision 4.94065645841247E-324 to
floating-point) 1.79769313486232E308 for positive values

Currency 8 bytes -922,337,203,685,477.5808 to


(scaled integer) 922,337,203,685,477.5807

Decimal 14 bytes +/-79,228,162,514,264,337,593,543,950,335


with no decimal point;
+/-7.9228162514264337593543950335 with 28
places to the right of the decimal; smallest non-
zero number is
+/-0.0000000000000000000000000001

Date 8 bytes January 1, 100 to December 31, 9999

Object 4 bytes Any Object reference


String 10 bytes + 0 to approximately 2 billion
(variable- string
length) length
String Length of 1 to approximately 65,400
(fixed-length) string
Variant 16 bytes Any numeric value up to the range of a Double
(with numbers)
Variant 22 bytes + Same range as for variable-length String
(with string
characters) length
User-defined Number The range of each element is the same as the
(using Type) required by range of its data type.
elements

In this table, we see that each variable has different ranges, some larger than
others, and in the same time the size storage varies too. The smallest unit of
memory available is called a byte, and according to this table it goes from
number 0 to 255.
Let’s do this to start:
1. Enable the Design Mode Button, which is next to the Insert Button in
the Developer TAB.
2. Double click on the ActiveX Button.
3. Now you’re ready to write the code for it.

Private Sub CommandButton1_Click()


End Sub
That’s what you should see.
Now let’s write some code between those lines we see:

Private Sub CommandButton1_Click()


Dim X As Byte
Dim Y As Byte

X=1
Y = Range("B1")
Do
Range("A" & X) = Y
X=X+1
Y = Y + Range("B1")
Loop Until X = 101
End Sub

This is the meaning of this code. It says:


Private Sub CommandButton1_Click()
Private means that you won’t find the code in the Macros Button.
CommandButton1 is the default name given to the ActiveX Button, and Click
means that the code below will be applied only when you click on it.
Dim X As Byte
Dim declares variables, So, it says that X is a variable that will be used
with numbers from 0 to 255, because “Byte” only accepts that range
according to the table above.
X=1
I added the initial value for the variable, which will be 1.
Y=Range(“B1”)
Means that the value of the variable Y is the same value as cell B1.
Do
Means do this.
Range(“A” & X) = Y
We already declared X as a variable with a value of 1. So, the Range
AX means Range(“A1”)=Y, and Y is the Range (“B1”). If I add the number
5 to B1, then Y = 5. So, finally it is Range(“A1”)=5.
X=X +1
It means that X=1+1 because in that moment X=1, so finally X=2. The next
time this process repeats, it will be X=X+1 again, but this time X=2, so
finally X=3, because X=2+1, and so on.

Y = Y + Range("B1")
This will follow the same process as the last step, but with the value added in
Range(“B1”) which will be that one we added. If B1 has a 5, then it will add
another 5, following a sequence according to what we wrote on B1.
Loop Until X = 101
It means that the same process between Do and LOOP will be repeated until
X=101.
End Sub
Means the end of the procedure.

Let’s try it now!


Add the number 1 to the cell B1 and press the button. You’ll see that it fills
up the cells from A1 to A100 one by one. Try it with two, and you’ll see that
it adds from A1:A100 two by two. Finally add the number 3 and press the
button.
Congrats! You’ve found your first bug! It is an overflow.

Bugs are errors when one writes a wrong code. In our example the code
works fine with numbers from 0 to 255 only, and once we ask the file to go 3
by 3 one hundred times we are expecting it to go from 3 to 300, which is
more than 255, so it causes an overflow.
To fix it, we have two options, we increase the value of the variable or we let
Excel to add it automatically.
Let’s consider the possibility of increasing the capacity of the variable, we
can change it from byte (0 to 255) to integer (-32,768 to 32,767). It will be
great if we were pretty sure that we won’t work with higher numbers of
32,767, or even change it to “long” which goes from -2,147,483,648 to
2,147,483,647. It would be great to work even with millions, but let’s
imagine that someone needs to put billions in B1. In that case even a long
variable wouldn’t be enough. So, the best way to solve this is don’t declare
the variable and leaving the code in the following way:
Private Sub CommandButton1_Click()
Dim X As Byte
X=1
Y = Range("B1")
Do
Range("A" & X) = Y
X=X+1
Y = Y + Range("B1")
Loop Until X = 101
End Sub

Or declaring the value as Variant, which let any number or letters.

Private Sub CommandButton1_Click()


Dim X As Byte
Dim Y As Variant
X=1
Y = Range("B1")
Do
Range("A" & X) = Y
X=X+1
Y = Y + Range("B1")
Loop Until X = 101

End Sub

What is the advantage of declaring variables as byte, integer or any


other?
Maybe you are wondering why to declare a variable as byte or integer, etc. If
Excel can add one automatically as in the example we’ve seen?
The answer is simple and important to know. Let’s remember that a variable
as byte stores in RAM Memory only 1 byte, which is the smallest amount of
memory possible in Excel, but a variant declared as variant stores at least 22
bytes. If we don’t declare a value in which we are sure won’t add more than
the needed values, it will consume more RAM, it will cause a program to run
slow in very simple tasks.
For example, I need to declare 1000 variables as byte. It would consume 1
Kilobyte of RAM only.
But By default, if you don't supply a data type, the variable is declared as
Variant data type, which consumes 22 bytes + string length, string length is
for letters.
So, 1000 variables not declared would be automatically declared as variant,
and it would consume 22 kilobytes. It is 21 empty kilobytes, which is 95% of
not available space and don’t used at all in case we would have required them
as bytes instead. If you are going to program in VBA and want your program
to run smoothly, you better learn what kind of variable to declare. Otherwise,
it will probably take long to load and then will run slow.

Require Variable Declaration Importance

Probably, one of the biggest problems about not declaring a Variable are
creating bugs, because we simply type something wrong. Let’s make a simple
example of it.

1. Open Visual Basic


2. Double Click on ThisWorkbook
3. Add the following code:

Public Sub Infinite()


myvariable = 200
myrange = 1
Do Until myvariabe = 300
Range("A" & myrange) = myvariable
myvariable = myvariable + 1
myrange = myrange + 1
Loop
End Sub

As you see it is a very similar code to one we did before. It should stop once
myvariable equals 300, but it continues. Can you see the problem?
If not, run the code. You’ll notice that it will go beyond 300, and practically
will have no end, or at least until it has no more files. In Excel 365 the total
files available is 1048576, so it will go until A1048576 and will enter on an
error.
If you don’t want to wait until that, Press ESC Key which will interrupt the
code execution and then press End Button.

Well, the problem is that we miss just one letter of a variable. We named it
myvariable but when coding we miss the letter L : Do Until myvariabe. Excel
identified myvariable and myvariabe as two different variables, and
automatically assigns them as Variant type.
What would have happened if your code has a lot of code? To find the
problem you should look at all your code to find the letter you missed! As
you see it would be a big trouble! That’s why Microsoft Excel has an option
called Require Variable Declaration.
It won’t let you write anything which is not code or a declared variable. To
enable this feature do the following:

1. Visual Basic
2. Tools Tab
3. Options
4. Require Variable Declaration
5. Ok.

It will add something above the code, which says Option Explicit. But, you
won’t see that change until you start a new project, insert a module or you
write it by yourself. That’s why it is important to start a new project always
with this option enabled.
In this case, add Option Explicit manually above the code.

Option Explicit
Public Sub Infinite()
myvariable = 200
myrange = 1
Do Until myvariabe = 300
Range("A" & myrange) = myvariable
myvariable = myvariable + 1
myrange = myrange + 1
Loop
End Sub

After you added this code Run it!


You’ll see that it automatically displays a message saying Variable Not
Defined and even highlight the problem. So, you can see that it will avoid
further problems for misspell variables.

APPs Performance

Now, imagine that you really need to fill one by one all the cells from A1 to
A1048576, and that it is one of the functionalities your APP should do.
Almost always Developers are concerned about creating Apps which run fast.
In Excel it is not an exception. Try running the following code and see how
long it takes to fill all column A with numbers:

Public Sub FillColumnA()


Dim X As Long
X=1
Do Until Range("A1048576") <> Empty
Range("A" & X) = X
X=X+1
Loop
MsgBox "Finished"
End Sub

When it finishes it will display a message saying “Finished”. It will probably


take about 5 minutes, maybe less or more depending on your computer
performance. You probably will notice Excel saying that it is not responding,
but in most cases it is still working. I don’t want to wait too long!
A good way VBA Developers make Apps run faster, is by disabling the
ScreenUpdating. Every change Excel does we are supposed to see it. But, if
we don’t want to see it, it will definitively improve its performance.
Let’s change the code to this:
Public Sub FillColumnA()
Dim X As Long
On Error GoTo A
Application.ScreenUpdating = False
X=1
Do Until Range("A1048576") <> Empty
Range("A" & X) = X
X=X+1
Loop
A:
MsgBox "Finish"
End Sub

Run it and time how long it takes, then compare how faster this way is. Don’t
forget to erase Column A before you start. You should notice a big
difference! Screenupdating is a great tool when need to increase an App
performance. However, now go to the spreadsheet and try to do something.
You should notice that it is not possible to do anything, or at least you won’t
see that, because screenudating = false turned off the visibility changes. So,
when you use Application.screenupdating = false NEVER forget to add
Application.ScreenUpdating = True at then end of your code, and even better
as a backup in case of error do as the code below:

Public Sub FillColumnA()


Dim X As Long
On Error GoTo A
Application.ScreenUpdating = False
X=1
Do Until Range("A1048576") <> Empty
Range("A" & X) = X
X=X+1
Loop
A:
Application.ScreenUpdating = True
MsgBox "Finished"
End Sub
MSGBOX

As you saw in the code above, it displays a message saying “Finished”. We


can do much more than that!
One of those messages can execute code too! Look at the table below:

Constant Value
vbOK 1
vbCancel 2
vbAbort 3
vbRetry 4
vbIgnore 5
vbYes 6
vbNo 7

Those are the kind of messages you can display, and once you click on it, it
will return the value according to the table above.
Run the following code:
Public Sub fff()
Dim X As Byte
X = MsgBox("This is the body",
vbYesNoCancel, "This is the title")
MsgBox X
End Sub
It will display a msgbox with a Yes, No and Cancel button. Once you click
on any button, X will take that value and will display it on the next MsgBox.
So, if you click on Yes, you’ll see a number 6, and if you click on No, you’ll
see a number 7.
This is a great advantage, because we can ask if user want to proceed or
not, etc.

If and Select Case

We see that once we are adding a msgbox, we can also create a warning
message, or information, or critical, etc. Let’s combine one in the code
below, so we can figure out how to do it:

Public Sub myMessageBox()


Dim X As Byte

X = MsgBox("I'll tell you the button you pressed on", vbYesNoCancel +


vbExclamation, "What Button would you press?")
If X = 2 Then
MsgBox "You Pressed Button Cancel"
ElseIf X = 6 Then
MsgBox "You pressed Button Yes"
Else
MsgBox "You pressed Button No"
End If

End Sub
It will tell you the button you pressed. It means that if you can know
what button is pressed on then you can control an action according to it. For
Example execute a Macro.

If is the conditional. Like:


Public Sub Evaluation()
Dim X As Byte

X = Range("A1")
If X = 5 Then
MsgBox "There's a number " & X
ElseIf X = 6 Then
MsgBox "There's a number " & X
ElseIf X = 7 Then
MsgBox "There's a number " & X
ElseIf X = 8 Then
MsgBox "There's a number " & X
Else
MsgBox "There's another value"
End If
End Sub
So “if” makes a conditional, “elseif” is checked in case the first condition
doesn’t meet, and will check as many “elseif” as you add until one condition
meet. “Else” will run in case any condition doesn’t meet. So, if we don’t add
any number from 5 to 8, we’ll see a message saying “There’s another value”,
but if we put a number 8, then we’ll see a message saying There’s a number
8.
If, elseif and else are very similar to another kind of code called Select Case,
Case, and Case Else However, this one is more efficient than IF in some
cases. Let’s do the same than above but using case instead:

Public Sub Cases()


Dim X As Byte
X = Range("A1")
Select Case Range("A1")
Case 5 To 8
MsgBox "There's a number " & X
Case Else
MsgBox "There's another value"
End Select
End Sub

This last one occupies much less code. It was easier and better. You can do
practically the same but is up to you which one you want to use.
Quiz 3

What is a Variable?
a) It is a value which never changes.
b) It is a value which changes.
c) It is a special number.

What is the storage size of a byte variable and its range?


a) It stores 2 bytes and goes from -32567 to 32567.
b) It stores 1 byte and goes from -256 to -256.
c) It stores 1 byte and goes from 0 to 256.

What is the advantage of declaring variables?


a) It consumes less RAM and makes it run smoothly.
b) It consumes more RAM and makes it run slower.
c) It wouldn’t work if variables aren’t declared.

Is it obligatory to declare variables?


a) Only if Require Variable Declaration is enabled
b) It is obligatory in all circumstances
c) It is not, Excel declares them automatically according to the value
added.

Msgbox returns a value depending on the button pressed:


a) We assign the value to each button
b) It returns a value depending on the button pressed
c) Values aren’t returned
CHAPTER 4
Project: Creating a Simple Calculator using
ActiveX

We’re going to create a simple calculator first. After this project is


completed, we’ll create a more sophisticated one. To do that, we’ll require to
know the following:

What is a Module?
When we start writing VBA code, we’ll usually start writing on Sheet1. But,
in order to understand Modules, Procedures Private and Public, we’ll create a
visual calculator. First, we´ll do it on a spreadsheet, and then we’ll do it as a
real program.

A module, is something like a Box, in which we add some code to run when
we “call” it. To understand how it works, we’ll create our calculator using a
few Modules.

How to create a Module


First, add the following ActiveX buttons on a spreadsheet on the table as it is
shown on the image. To add the appropriate symbol to each button, it is not
as we did on the Form Buttons. In this case we have to click on the Design
More Button, which is in the developer TAB, then right click on each button
and you’ll see something like the image below, in which we see something
called “Name”. Most people would think that there’s where we can add the
correct symbol to see, but that’s wrong. Excel identify the Button with that
name. Imagine you have several buttons with + as their name. How would
either Excel or you identify which one is the correct? So, every button will
have a different name, let’s add a good one which let us know what it does
like In the example I wrote cmdAddition. It lets me know that that it applies

to the “+” Button. However, how can I add the sign +?

In the image above, you ‘ll see that there’s a property called Caption. That’s
where You’ll add the “+” sign.
You can even play a little bit with the other options, like the Backcolor, Font,
Height and even add a picture. I left all options as they were by default.

Once you repeated the process for all the buttons, let’s start with the next
steps. Let’s create a Module!
Follow these steps:

1. Open Visual Basic through the Developer TAB. By default you’ll see
something like this:

2. Click on “View TAB” and select “Properties Window”. We’ll always


use this window a lot. Now you should see something like what’s
shown inside the red square:
3. Let’s add our first Module. Click on Insert TAB, then Module.

4. You’ll see a New Folder Called “Modules” with a file there Called
“Module 1”:

5. Select it and in the Properties Window Change its name to Addition,


then repeat the process until you have created a Module for Minus,
Division and Times.
6. Double click on the Module “Addition” to open it.
7. You’ll see that it displays an entire blank sheet. We need to add a
Procedure! To do that, click on Insert TAB, then Procedure. It will
display a window like this, add a name and leave the default options:

8. Click OK and you’ll see this:

9. Between those lines write the following code:

Range ("A2") + Range("B2") = Range("C2")

10. Now run it by clicking the green triangle above.


11. It is displaying an error saying: Invalid use or Property.
Maybe it is because we haven’t added any number in the cells A2 and
B2. Add them and run it again.

It is still having a problem! Can you see what’s wrong?

Welcome to your second bug! The problem here is a very usual one. We are
asking Excel that cells A2 + B2 are equals to C2 instead of C2 equals to A2 +
B2. This problem is just an order problem. You better don’t forget this rule!!
Always add first the cell you want to be changed, then add the values that
you’ll need. Like this:
Range("C2") = Range("A2") + Range("B2")

Run it again with the same green triangle.


OK! It works!

If you see a yellow line which doesn’t let you run it, just click stop, correct
your code and run it again.

Now you’ll see that in the cell C2 we find the result of A2+B2.

Let’s complete the other modules repeating the correct process above. Add
these codes to do that:

Minus Module:
Public Sub Minus()
Range("C2") = Range("A2") - Range("B2")
End Sub

Division Module:

Public Sub Division()


Range("C2") = Range("A2") / Range("B2")
End Sub

Times Module:

Public Sub Times()


Range("C2") = Range("A2") * Range("B2")
End Sub

You’re supposed to see a file like this:


All the modules should work if you run them.

Now, let’s link the Modules to their appropiate button.

To do that just do the following:

1. Go to the spreadsheet
2. Click on Design Mode
3. Double click each button. You’ll see that every time you do it, it adds
some code to the Sheet1(Sheet1). Finally, it should look like this:
Another Random Scribd Document
with Unrelated Content
unreasonably, as he paid sixty-four shillings into the pool, that the cards had
not been shuffled. Thus the Babe, who had dealt, had a pool of sixty-four
shillings to win or lose. He staked the pool, but he held one diamond, one
club, and the ace of spades, which counted below the two, and he wrote an I
O U for sixty-four shillings, as he had not got enough counters, and paid it
into the pool, remarking that this was better than whist at three penny
points. Then the pool in one deal had mounted from four shillings, to one
hundred and twenty-eight shillings, and it was obvious that if a similar deal
occurred again now, there would be a very considerable sum in the pool at
the end of it.
The Babe in these matters was, like the Athenians, somewhat
superstitious, and he said cheerfully that it was a mounting pool, and they
would have some amusement. The pool showed by its subsequent conduct
that he was right, and at the end of an hour it held about £50, about half of
which had been contributed by Feltham, whose luck had been abominable.
This, as they were playing at present, might be won by anybody, since there
was no limit to the stakes, and the Babe, with the best possible motives,
since he was the only one present who would not be somewhat embarrassed
by the total loss of his contribution to the pool, proposed setting a limit, of,
say, twenty-five shillings to the stake. Feltham objected strongly, and the
alteration was vetoed.
Everyone, with the exception perhaps of the Babe, was a little excited
and on edge, for when two or three are gathered together to gamble they
often generate spontaneously between them—this is a sober fact—a little
demon which hovers about and unsettles their nerves. Feltham especially
hardly spoke, except to name his stake, and sometimes to swear when he
lost it, and the Babe felt that they were all taking it too seriously and quite
spoiling his pleasure. For himself, he liked a “little game” because it
happened to amuse him, but the others were behaving as if they cared
whether they won money or lost money, and this, to the Babe’s thinking,
spoilt the whole thing. The point of gambling, according to him, was not
whether you won money or lost money, but the moment when it was
uncertain whether you were going to win (in the abstract) or lose (in the
abstract). The view is wholly unreasonable, and so is the gambling instinct.
It was Broxton’s turn to deal. He dealt badly, holding the pack from
which he dealt nearly a foot above the table, so that if any of them
happened to be looking at the cards as they were dealt to him, the chances
were that he would get a glimpse or a hint of what the under one was, and
once before that evening the Babe had demanded a fresh deal, because as
his cards were dealt him, he could not help seeing the corner of a picture
card. This time, however, he was handing a cigarette to Feltham, who sat on
his right. But as Feltham’s cards were dealt him the Babe saw him look up
quickly, and he himself saw the face of one of them, so far, at least, that he
would have been ready to swear it was a picture card in clubs. Feltham at
the moment seemed to him to open his mouth to speak, but said nothing and
only glanced hurriedly at the Babe, who did not look at him again during
the game. The turn-up card was the nine of clubs.
The first two players naturally enough, as there were only four cards out
of fifty-two which could beat the nine, staked a nominal stake merely, and
turned up their cards. One of them held the king of clubs, and this would
have won, leaving only three cards in the pack which could win. He took a
shilling, the amount of his stake, out of the pool, and said he wished he had
trusted to his instinct. It was Feltham’s turn. He staked £20, which was
madness. His hand contained the queen of clubs and he won.

Very soon after, the Babe renewed his proposition that they should limit
the stakes, and this time there was no opposition, and as it was already after
one, they settled to stop as soon as the pool had been emptied. The pool,
seeing them change their tactics, also changed its own, and instead of
mounting continued to sink steadily. Every now and then it would go up
again by a couple of limit stakes, but the constant tendency was to sink, and
in three-quarters of an hour it was empty. Broxton gathered up the cards and
counters, and Feltham and two of the others said “Good-night,” and left the
room, but Anstruther and the Babe sat down and waited. The Babe helped
himself to whisky, tore up his own I O U’s which he had paid for, and there
was a long awkward silence.
Broxton got up, closed the door, and came and stood in front of the fire.
“That fellow cheated,” he said at last. “I saw him, twice. Did you notice,
Babe?”
“I thought he saw the cards which were dealt him once. The turn-up was
a nine of clubs and he staked £20. It struck me as unusual, particularly as
the king was already out.”
“Then he cheated twice, as Jim said,” answered Anstruther. “I am
convinced he saw his cards once before, both times when Jim was dealing.”
“Jim, you damned fool,” said the Babe, “why can’t you manage to deal
properly?”
“We’re all damned fools, I think,” said Broxton. “What business have we
got to ask a fellow to play whom we don’t know, and who probably can’t
afford it.”
“Nor can I,” said Anstruther, “but I don’t cheat.”
“Are we quite sure he did cheat?” asked the Babe.
“Personally, I am,” said Broxton, “aren’t you, Anstruther?”
“Good Lord, yes.”
“Well, what’s to be done?” asked the Babe.
“The men who play with him ought to know,” said Anstruther.
The Babe got up, and threw his torn-up I O U’s into the fire.
“Rot,” he said. “We can’t possibly be certain. And I’m not going to ask
him to play again in order to watch him. That seems to me perhaps one
degree lower than cheating oneself. It’s our own fault, as Jim said, for
asking him.”
“My dear Babe, we can’t leave it as it is.”
“No, I don’t want to do that. I only meant that we couldn’t tell other
people what we suspected, unless we were certain, and not even then. And
we can’t be certain unless we play with him again, and that I don’t mean to
do.”
“What do you propose to do then?”
“I propose that one of us tells him what we thought we saw.”
“And if he denies it?”
“The matter ends there. At the same time to make it clear to him that
three people separately thought they saw him.”
“Thought they saw him!” said Broxton.
“Certainly. Thought they saw him. I daresay he isn’t a bad chap. I
daresay he was playing for far more than he could afford. It is even possible
he will confess he did cheat, and it is quite possible that we are all wrong
and that he didn’t. Personally I certainly thought he did, but I wouldn’t take
my oath on it.”
“Who’s to ask him?”
There was a short silence. Then—
“I will, if you like,” said the Babe.
“Thanks, Babe,” said Jim, “you’d do it better than either of us.”
The Babe lit a cigarette, and finished his whisky.
“I’m off to bed,” he said, “I would sooner have played ‘old maid’ than
that this should have happened. Of course none of us say a word about it?
Good-night, you chaps.”
Anstruther and Broxton sat on for a bit after the Babe had gone.
“It’s a devilish business,” said the latter at length. “But I’m sure the Babe
will manage it as well as it can be managed.”
“The Babe isn’t half a bad chap,” said Anstruther.
“No, I don’t think he is. In fact, I don’t think I ever knew a better. Are
you off? Good-night.”
The Babe wrote a note to Feltham next morning asking him if he would
be in at seven that evening, and receiving an affirmative answer, it thus
came about that he tapped at his door at that hour.
XVIII.—The Confession.
Qui s’accuse, s’excuse.
From the French.

The Babe’s supposition that Feltham “perhaps wasn’t a bad chap” was
perfectly correct. At the same time it is perfectly true that he had cheated at
cards, which, quite rightly, is one of the few social crimes for which a man
is ostracised.
He had cheated, and he knew it, and he was thoroughly, honestly, and
unreservedly ashamed of it. He did not try to console himself by the fact
that he had never done it before, and by the knowledge that he would never
do it again, because he knew that he would fail to find the slightest
consolation in that, though it was perfectly true. The thing was done and it
was past mending. Twice he had seen the cards, or at any rate had a
suspicion of one of them, when they were dealt him, without saying
anything. On one of these occasions what he had seen did not help him, for
he saw only a card of another suit, but once, when he had seen the queen of
clubs, he traded on it, and swindled the company of £20.
How he had come to do it, he did not know. He thought the devil must
have taken possession of him, and he was probably quite right. The
temptation was the stronger because he had lost, as the Babe had suggested,
much more than he could afford, and the thing was done almost before he
meant to do it. He more than half suspected that the Babe had noticed it, but
to do him justice this suspicion weighed very light in his mind, compared
with the fact that he had cheated.
Next morning the Babe’s note came, and his suspicion that the Babe had
noticed it took definite form. It was no manner of use refusing to see him,
but what he could not make up his mind about, was what answer he should
give him. To confess it would not help him to make reparation, and to
return, as he honestly wanted to do, the £20 he had won and besides it did
not seem, in anticipation, particularly an easy thing to do. And when the
Babe knocked at his door, he was still as much in the dark as ever, as to
what, if the Babe’s errand was what he suspected, he should say to him.
The Babe accepted a cigarette, and sat down rather elaborately. He had
determined not to remark upon the weather or the prospects of an early
dissolution, or make any foolish attempts to lead up to the subject, and after
a moment he spoke.
“I am awfully sorry,” he said, “to have to say what I am going to. In two
words it is this: Three men with whom you were playing last night at
Marmara, thought that once or twice you saw your cards, or one of your
cards, before you staked. I am one of them myself, and we decided that the
only fair and proper thing to do was to ask you whether this was so. I am
very sorry to have to say this.”
The Babe behaved like the gentleman he was, and instead of looking at
Feltham to see whether his face indicated anything, kept his eyes steadily
away from him.
Feltham stood a moment without answering and if the Babe had chosen
to look at him he would have seen that he paused because he could not
command his voice. But the Babe did not choose to do so. Feltham would
have given anything that moment to have been able to say “It is true,” but it
seemed to him a physical impossibility. On the other hand he felt it equally
impossible to take the high line, to threaten to kick the Babe out of the room
unless he went in double quick time etc., etc.,—to do any of those things
which thorough-paced swindlers are supposed to do when their honour is
quite properly called in question.
“It is a damned lie,” he said at length, quite quietly and without
conviction.
The Babe got up at once, and stepped across to where Feltham was
standing.
“Then I wish to apologise most sincerely both for myself and the other
two fellows,” he said, “and if you would like to knock me down, you may. I
shall of course tell them at once we were mistaken, and I believe what you
say entirely. Will you shake hands?”
Feltham let the Babe take his hand, and as the latter turned to leave the
room, sat limply down in the chair from which the Babe had got up.
But the Babe had hardly got half-way across the room, when Feltham
spoke again.
The Babe’s utter frankness had suddenly made it impossible for Feltham
to let him go without telling him, but to tell him now was not made easier
by having lied about it.
“Please wait a minute,” he said.
The Babe’s cigarette had gone out, and he lit it again over the lamp.
Then he sat down in the window seat and waited. Outside, the grass was
sparkling with frost and the clock chimed a quarter past seven.
Simultaneously Feltham spoke:
“I have lied to you as well,” he said. “What you saw was perfectly true. I
cheated twice, at least I saw one of the cards dealt me twice, and said
nothing about it. Once the card happened to be immaterial, and once I
staked £20 knowing I should win. I have told you all.”
The Babe was a person of infinite variety, and if those who knew him
best had seen him now, they would hardly have believed it was he. He sat
down on the arm of the chair where Feltham was sitting, and to himself
cursed the whole pack of cards from ace to king, and above all Jim Broxton.
Then aloud—
“My poor dear fellow,” he said. “I’m devilish sorry for you.”
Feltham, who had been expecting to hear a few biting remarks or else
merely the door slam behind the Babe, looked up. The Babe was looking at
him, quite kindly, quite naturally, as if he was condoling with him on some
misfortune.
Feltham began, “Damn it all—” then stopped, and without a moment’s
warning burst out crying.
The Babe got up, went to the door and sported it. Then he sat down
again on the arm of the chair.
“Poor chap,” he said. “It’s beastly hard lines, and I fully expect it’s as
much our fault as yours. You needn’t trouble to tell me you never did it
before: of course you didn’t. I fully believe that. People who would confess
that sort of thing don’t do that sort of thing twice. It was like this perhaps—
we were playing for far more than you could afford, and you didn’t mean to
do it, until somehow it was done. Money is a devilish contrivance.”
“Yes, it was just like that,” said Feltham. “As I told you, the first time I
saw a card, it didn’t make any difference, though of course I ought to have
said so. But the second time it did, and before I knew what I had done, I had
cheated. Why don’t you call me a swindler and tell me I’m not fit to
associate with gentlemen? It’s God’s truth.”
The corners of the Babe’s mouth twitched.
“It’s not my concern then. What would be the good of saying that?”
He paused a moment, hoping that Feltham would make a certain
suggestion, and he was not disappointed.
“Look here, there’s the twenty pounds: what can I do with it? Can you
help me?”
The Babe thought a moment.
“Yes, give it me. I’ll see that the other fellows get it somehow, if you’ll
leave it to my discretion. And, you know, it sounds absurd for a fool like me
to give advice, but if I were you I shouldn’t play cards for money again. It’s
no use running one’s head into danger. If it’s not rude, what is your
allowance?”
“Two hundred and fifty.”
“You bally ass! Yet I don’t know. It’s our fault. You couldn’t tell that the
pool would behave in that manner, and I know, personally, I should find it
out of the question to say one was playing for more than one could afford.
Some people call it moral cowardice, it seems to me a perfectly natural
reticence.”
“Of course I won’t play again,” said Feltham. “Why have you been so
awfully good to me?”
“I haven’t. What else was I to do? Oh, yes, and I think I respected you
for telling the truth. Most fellows would have lied like George
Washington.”
Feltham smiled feebly.
“All that remains is this,” said the Babe. “Of course I must tell those
other two fellows about it, the two I mean with whom I talked, but you can
trust them absolutely. It is impossible that anyone else should ever know
about it.”
“You don’t think—oughtn’t I to tell them all?” stammered Feltham.
The Babe frowned.
“Of course you ought not. Why the deuce should you? About the money
—it must be divided up between us all. Six into twenty, about three pound
ten each. Rather an awkward sum.”
“Why six?”
“Because there were six of us.”
“I can’t take any.”
“Your feelings have nothing to do with it,” remarked the Babe. “The
money in the pool of course belongs to everyone. You return the others’
shares of that £20 and keep your own. Well, I’ll manage it somehow. I will
make absurd bets, seventy to one in shillings. That will surprise nobody: I
often do it. Good Lord, it’s a quarter to eight. If you’re going into Hall,
you’ll be very late, and so shall I for my dinner. I must go. Oh, by the way,
did you lose much altogether?”
“About twenty-five pounds.”
“Is it, is it”—began the Babe. “I mean, are you in a hole? If so, I wish
you’d let me lend you some money. Why shouldn’t you? No? Are you sure
you don’t want some? It’s no use receiving unpleasant letters from one’s
father, when there’s no need. Well as you like. Good-night. Come round and
look me up some time: I’m on the next stair-case.”
Feltham followed him to the door.
“I can’t tell you what I feel,” he said huskily, “but I am not ungrateful.
Half an hour ago you asked me to shake hands with you. Will you shake
hands with me?”
“Why, surely,” said the Babe.
XIX.—In the Fifties.

He sailed his little paper boats,


And when the folk thought scorn of that,
He spudded up the waiting worm
And yearned towards the master’s hat.
Hotch-potch Verses.

The Babe went off to dress for dinner much relieved in mind. Now that
it was over he confessed to himself that he had been quite certain that
Feltham had cheated, but that he should own up to it, was fine, and the
Babe who considered himself totally devoid of anything which could
possibly be construed into moral courage, respected him for it. He also
registered a vow that never to the crack of doom—which cracked three days
afterwards—would he play unlimited Marmara again, and told himself that
he was not cut out for the sort of thing that he had just been through, and
that he was glad it was over. He went round at once to tell Broxton and
Anstruther what had happened, and after that shook the whole

CLARE COLLEGE AND BRIDGE.


affair from his mind, as a puppy shakes itself after being in the water.
He was, naturally, late for dinner, and Mr. Stewart who knew the value
of soup and also the habits of the Babe, had not waited. When he did
appear, he was, of course, perfectly unabashed, and took the bottom of the
table with unassuming grace.
“The psychology of punctuality,” he remarked, “is a most interesting
study. Some day I mean to study it, and I shall write a little monograph on
the subject uniform with those which Sherlock Holmes wrote on tobacco
ash and the tails of cart horses. I think there must be a punctuality bacillus,
something like a death-watch, always ticking, and if there isn’t one, I shall
invent it. It doesn’t take to me. I am too healthy.”
“My dear Babe,” said the Stewart, “you have disappointed me. I always
hoped that you were the one person I have been looking for so long, who
has never been punctual; But you have been punctual to my knowledge
twice, once on an occasion in the Long——”
“When was that?” interrupted the Babe. “I don’t believe it.”
“On a memorable occasion. At lunch in your own rooms.”
The Babe caught Reggie’s eye, and looked away.
“Oh, yes.”
“And as Clytemnestra, you always killed Agamemnon with ruthless
punctuality. I was always hoping to hear him scream during the next Chorus
but one.”
“I did the screaming for him,” said the Babe complacently, “except on
the first night. He could only scream like an empty syphon.”
“There is nothing more tragic or blood-curdling than the scream of an
empty syphon,” said Stewart. “It shrieks to you, like a banshee of all the
whisky and soda you have drunk. The only thing that could shriek worse
would be an empty whisky bottle, and that can’t shriek at all. If he really
could scream like that, you robbed him of a chance of greatness by
screaming for him, although you screamed very well.”
“There are syphons and syphons,” said the Babe, “he screamed like an
empty but undervitalised one, which had never really been full.”
“Babe, if you talk about undervitalised syphons during fish,” said
Reggie, “you will drive us all mad, before the end of dinner.”
“Going mad,” said Mr. Stewart, “is an effort of will. I could go mad in a
minute if I wished, and the Babe certainly determined to go mad when he
was yet a boy. No offence meant, Babe. I can confidently state that during
the three years I have known him, he has never for a moment seemed to be
really sane.”
“I was perfectly sane when I settled to go in for the tripos,” said the
Babe.
“You never settled to do anything of the kind. You think you did and it is
one of your wildest delusions.”
“Secondly I was sane,” said the Babe, “when I—”
“No you weren’t,” put in Reggie.
“Reggie, don’t be like Longridge. But you are quite right. I wasn’t sane
then, though I thought I was for the moment.”
“Longridge is better, though he still has a large piece of sticking plaster
over his nose,” said Mr. Stewart. “He came to see me to-day. He insisted on
arguing with me in spite of my expostulations. When he talks, I always
want to cover him up, as one covers up a chirping canary.”
“I wish you would do it some day. With a piece of green baize you know,
and a hole in it where the handle of the cage comes out.”
“He would continue to make confused noises within,” said Reggie.
“He always makes confused noises,” said Mr. Stewart wearily.
“Confused, ingenious, noises. Babe, tell me if that champagne is drinkable.”
The Babe drank off his glass.
“Obviously,” he said. “But it’s no use asking me: all champagne seems
to me delicious. I drink Miller’s cheapest for choice.”
A small withered don who was sitting next the Babe, and had not
previously spoken, here looked up.
“A nice, dry, light wine,” he said.
The Babe started violently, and if he had not just emptied his glass of
champagne, he would certainly have spilled it. He explained afterwards that
he really had forgotten that anyone was occupying the chair on the right.
This curious old gentlemen, one of the few surviving specimens of this
particular type of elderly don had the classical name of Moffat, and Mr.
Stewart at once introduced him to the Babe, a ceremony which had escaped
his memory before, and Mr. Moffat who had been shivering on the brink of
conversation all dinner, decided to plunge in.
“I saw your performance of the Agamemnon last week,” he said.
“I hope you enjoyed it,” said the Babe politely.
“The stage is not what it was in me young days,” said Mr. Moffat.
The Babe looked interested and waited for further criticisms, but the old
gentleman returned to his dinner without offering any. His face looked as if
it was made of cast iron, painted with Aspinall’s buff-coloured enamel.
There was a short silence, and Mr. Stewart, looking up, saw that the
Babe was fighting like a man against an inward convulsion of laughter. His
face changed from pink to red, and a vein stood out on his usually
unwrinkled brow. Stewart knew that when the Babe had a fit of the giggles
it was, so to speak, no laughing matter, and he made things worse by asking
Mr. Moffat how his sister was. At this point the Babe left the room with a
rapid, uneven step, and he was heard to plunge violently into the dishes
outside. Stewart had been particularly unfortunate in his choice of a subject,
because what had started the Babe off, was the very thought that Mr.
Moffat’s sister was no doubt the original Miss Moffat, and he had been
rashly indulging in wild conjectures as to what would happen if he said
suddenly:
“I believe your sister doesn’t like spiders.”
Mr. Moffat had resumed the subject of the Greek play when the Babe
returned—he seemed not to have noticed his ill-mannered exit—and was
finding fault with the chorus, particularly with the leader, who, in the person
of Reggie, was sitting opposite him. Of this, however, he had not the
slightest idea.
“I call them a dowdy crew,” he said. “They were dressed like old baize
doors. Not me idea of a chorus at all. But it was all very creditable, very
creditable indeed, and we have to thank me young friend here for a very
fine performance of Clytemnestra. Why, me sister”—here the Babe gasped
for a moment like a drowning man, but recovered himself bravely—“me
sister came down next morning at breakfast, and said she’d hardly been able
to sleep a wink, hardly a wink, for thinking of Clytemnestra.”
The Babe made a violent effort and checked himself.
“I’m so sorry,” he said, with his most engaging manner. “I hope you will
apologise to her for me.”
“Not at all, not at all,” said Mr. Moffat. “It’s me own opinion she slept
far more than she knew. But she was always nervous,”—the Babe bit his
tongue—“easily upset. A very good pheasant, Mr. Stewart, a very good
pheasant. Thank ye, yes, a glass of champagne. A glass of wine with you,
heh, heh, Clytemnestra.”
Mr. Moffat, as the Babe allowed afterwards, was a very pleasant old
gentleman. When dinner was over and he had settled himself into an arm-
chair by the fire, smoking one of Stewart’s strongest cigars, he told several
stories about the old generation of dons whom he had known.
“There was an old fellow of King’s” he was saying, “in me
undergraduate days, who must have been eighty, and never a night had he
spent out of Cambridge since he came up as an undergraduate. An infidel
old lot he was. Many a time I’ve seen him in the evening, when the worms
were come out on the grass plot, hobbling about and trying to kill them with
the point of his stick. He used to talk to them and make faces at them and
say, ‘Ah, damn you. You haven’t got me yet.’ A queer lot they all were, not
the worms I mean, heh, heh, but the old dons. There were two others who
had been great mathematicians in their time, and they used to spend their
evenings together doing, what do you think? Making paper boats, sir, which
they went and sailed on the Cam next day. They would start them from the
King’s bridge, and sail them down to the willow at the other end of the
lawn. And such quarrels as they had over which had won! One of them one
morning, his name was Jenkinson, if I’m not mistaken, an old
Yorkshireman, got so heated over it,—for he said the other boat had fouled
his, as if they were racing for a cup,—that he went for the other man, by
gad, sir, he went for him, and tried to push him into the river. But the other
—his name was Keggs—was too quick for him, and stepped out of the way,
and head over ears into the river went Jenkinson himself, being unable to
stop himself, sir, by reason of the impetus he had got up. The river isn’t
over deep, there, as you know, perhaps two feet deep, and he stood up as
soon as he could find his feet and bawled out: ‘Ah misdoot ye’ve drooned
me, Keggs.’ ”
The Babe was delighted.
“Do tell me some more,” he said, when Mr. Moffat had finished
laughing himself, which he did in a silent, internal manner.
“Ah, some of those old fellows did things not quite fit for boys to hear
about. Maxima reverentia, eh, Mr. Stewart? But there was an Irishman, a
fellow of Clare too, in my time. I might tell you about him; he used to live
in the rooms above the gate. He had a quarrel with the Master, and as often
as the Master went in and out of the gate, egad, the old chap would try to
spit on his head. If the Master was out to dinner, he would wait up, sitting in
his window till he came back, be it eleven o’clock or twelve, or later than
that. At last the Master had to put up an umbrella when he walked under the
gate of his own college and then the old fellow would shout out, ‘Come, out
o’ that, ye ould divil, and let me get at ye.’ A disreputable old crew they
were!—Ah well, it’s half-past ten. Eleven’s me bedtime, and I must be
going. Good-night to you Mr. Stewart, and many thanks for your kind
hospitality. And good-night to you, sir,” he said turning to the Babe; “I
heard them shout ‘Clytemnestra, good old Clytemnestra,’ after you all down
the street. And you deserved an ovation, sir, you richly deserved an ovation,
and I’m glad you got it.”
After Mr. Moffat’s departure, they settled down again, and Stewart
remarked:
“You’ve made a conquest, Babe. But you behaved abominably during
dinner.”
“I couldn’t help it. I could think of nothing but Miss Moffat. On the top
of that you enquired about his sister. I ask you, what was I to do?”
“You needn’t have danced in the dishes outside,” said Reggie.
“I only danced in the soup, and we’d finished with the soup. And there’s
a soupçon of it on my—”
“Shut up.”
“Pumps,” continued the Babe. “May I have some whisky? Thanks. For
what I’m going to receive. What a funny undergraduate Moffat must have
been.”
“I believe he was born like that,” said Stewart. “I know when I came up,
ten years ago, he was just the same. That’s the best of getting old early: you
don’t change any more.”
“That’s one for you, Babe,” remarked Reggie.
“The Babe is the imperishable child,” said Stewart.
“You called me a man of the world the other day,” said the Babe in self-
defence.
“I think not.”
“You did really. However, we’ll pass it over.”
“By the way, Babe, you are corrupting the youth of the college. Two men
went into their lodgings last night at ten minutes past two. It transpired that
they had been playing cards with you.”
“Well, it is true that I was playing cards last night. But they could have
gone away earlier if they had wished.”
“Your fascinations were probably too strong,” said Reggie.
“Now you’re being personal, and possibly sarcastic,” said the Babe with
dignity. “I must go to bed. I was late last night.”
“The night is yet young, Babe,” said Stewart.
“So am I. But if I don’t go, I shall continue to drink whisky and soda,
and smoke.”
“You are welcome. How is the tripos work progressing?”
“Oh, it’s getting on,” said the Babe, hopefully. “A little at a time, you
know, but often. I’m not one of those people who can work five hours at a
stretch.”
“I suppose not. Is it to be a second or a third?”
“I believe there are three classes in the tripos,” said the Babe stiffly.
“You have only mentioned two. Well, yes, perhaps one of your small
cigarettes would not hurt me. But I must go at eleven, because I am
sapping. Oh, isn’t that the Shop Girl on the table? There are some awfully
good songs in it. May I go and get my banjo?”
“Do. I got it expressly for you to sing.”
The Babe slept his usual eight and a half hours that night. He did not
awake till 10.30.
XX.—The Babe’s Minor Diversions.

Where three times slipping from the outside edge


I bumped the ice into three several stars.
Tennyson.

The frost continued, black and clean, and the Babe, like the Polar Bear,
thought it would be nice to practise skating. He bought himself a pair of
Dowler blades with Mount Charles fittings, which he was assured by an
enthusiastic friend were the only skates with which it was possible to
preserve one’s self-respect, and fondly hoped that self-respect was a
synonym for balance. Hitherto his accomplishments in this particular line
had been limited to what is popularly known as a little outside edge, but
Reggie who was a first-rate skater undertook his education. The Babe,
however, refused to leave his work altogether alone, for he was beginning
to be seriously touched with the sapping epidemic, and he and Reggie used
to set off about one, taking lunch with them, to the skating club, of which
Reggie was a member, and of which the Babe was not.
Sykes only went with them once, and he would not have gone then, had
it been possible to foresee that he would put skates in the same category as
croquet balls and bathers, but it was soon clear that he did. He made a bee-
line for the unemployed leg of Professor Robertson, who was conscious of
having done the counter rocking turn for the first time in his life without the
semblance of a scrape, and brought him down like a rabbit shot through the
head. The Babe hurried across to the assistance of the disabled scientist, and
dragged Sykes away. But Sykes had his principles, and as he dared not use
threats to the Babe, he implored, almost commanded him not to put on his
skates.
“Sykes, dear, you are a little unreasonable,” said the Babe pacifically.
“Reggie, what are we to do with Sykes? There was nearly one scientist the
less in this naughty world.”
The cab in which they had driven up, was still waiting, and at Reggie’s
suggestion Sykes was put inside and driven back to the stable where he
slept.
The Babe wobbled industriously about, trying to skate large, and not
deceive himself into thinking that a three was finished as soon as he had
made the turn, and Reggie practised by himself round an orange, waiting
for a four to be made up, until the Babe ate it.
About the third day the Babe was hopelessly down with the skating
fever, which went badly with the sapping epidemic. He took his skates
round to King’s in the evening, after skating all day, for the sapping
epidemic was rapidly fleeing from him like a beautiful dream at the
awakening, and skated on the fountain; he slid about his carpet trying to get
his pose right; he put his looking-glass on the floor and corrected the
position of the unemployed foot; he traced grapevines with a fork on the
tablecloth and loops with wineglasses; he dreamed that he covered a pond
with alternate brackets and rocking turns, and woke up to find it was not
true; he even watered the pavement outside his rooms in order to get a little
piece of ice big enough for a turn, with the only result that the bed-maker,
coming in next morning, fell heavily over it, barking her elbow, and
breaking the greater part of the china she was carrying, which, as the Babe
said, was happily not his. Unfortunately, however, the porter discovered it,
as he brought round letters, and ruthlessly spread salt thickly over it, while
the baffled Babe looked angrily on from the window.
Snow fell after this, and the Babe proposed tobogganing down Market
Hill. He talked it over with Reggie, and they quarrelled as to which was the
top of the hill and which the bottom, “for it would never do,” said the
scrupulous Babe, “to be seen tobogganing up hill,” and on referring the
matter to a third person, it was decided that the hill was perfectly level, so
that they were both right and both wrong, whichever way you chose to look
at the question.
The King’s Comby (which is an abbreviation for Combination and
means Junior Combination Room, but takes place in quite a different
apartment) went off satisfactorily. The Babe, secure in the knowledge that
there was no rhyme to Babe in the English language (his other name, which
I have omitted to mention before, was Arbuthnot, and it would require an
excess of ingenuity to find a rhyme even to that), made scurrilous allusions,
most of them quite unfounded, about his friends, in vile decasyllables, and
enjoyed himself very much. Later in the evening he with two of the
performers in the original play acted a short skit on the Agamemnon, in
which he parodied himself with the most ruthlessly realistic accuracy, and
killed Agamemnon in a sponging tin with the aid of a landing net and a pair
of scissors. Last of all he disgraced himself by stamping out in the snow, in
enormous letters, the initials of a popular and widely known don of the
college, with such thoroughness, that the grass has never grown since, and
the initials are to be seen to this day, to witness if I lie. The proceedings
terminated about three in the morning, and the Babe was left waiting for
some minutes outside the porter’s lodge at Trinity, while that indignant
official got out of bed to open the gate to him.
The Babe ought to have caught a bad cold, but with an indefensible
miscarriage of justice, it was the porter who caught cold, and not he, and the
Babe observed cynically, when he heard of it, that the memory of the dog in
the nursery rhyme, that bit a man from Islington in the leg, and then died
itself, had at last been avenged.
Christmas, the Babe announced, fell early that year, and consequently he
with several others stayed up till Christmas Eve, when they were allowed to
stay no longer. He had gone up to town for two days to play in the
University Rugby match, which he had been largely instrumental in
winning, for the ground was like a buttered ballroom floor, a state of things
which the Babe for some occult reason delighted in, and for an hour’s space
he proceeded to slip and slide and gloom and glance in a way that seemed
to paralyse his opponents, and resulted in Cambridge winning by two tries
and a dropped goal. The dropped goal was the Babe’s doing: theoretically it
had been impossible, for he appeared to drop it out of the middle of a
scrimmage, but it counted just the same, and he had also secured one of the
tries. The Sportsman for December 15th gives a full account of the match;
also the Babe’s portrait, in which he looks like a cross between a forger and
a parricide.
On returning to Cambridge, in order to be up to date, he and some
friends went out carol-singing one night, visiting the heads of colleges, and
the houses of the married fellows. The Babe acted as showman and spoke
broad Somersetshire, which interested a certain philologist, who had no
suspicion that they were not town people, very much. The Babe declared
that his father and grandfather had lived in Barnwell all their lives, and that
he himself had never even attempted to set foot out of Cambridgeshire
except once on the August Bank Holiday, when he had intended to go to
Hunstanton but had missed the train. At this point, however, the philologist
winked and said: “Mr. Arbuthnot, I believe.” They collected in all seventeen
Welcome to Our Bookstore - The Ultimate Destination for Book Lovers
Are you passionate about books and eager to explore new worlds of
knowledge? At our website, we offer a vast collection of books that
cater to every interest and age group. From classic literature to
specialized publications, self-help books, and children’s stories, we
have it all! Each book is a gateway to new adventures, helping you
expand your knowledge and nourish your soul
Experience Convenient and Enjoyable Book Shopping Our website is more
than just an online bookstore—it’s a bridge connecting readers to the
timeless values of culture and wisdom. With a sleek and user-friendly
interface and a smart search system, you can find your favorite books
quickly and easily. Enjoy special promotions, fast home delivery, and
a seamless shopping experience that saves you time and enhances your
love for reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!

ebookball.com

You might also like