Sie sind auf Seite 1von 38

A Primer on Mind Map, Flowchart

and Excel VBA


Prepared by:
Engr. Vandear J. Go Alcantara
PetE 31FE Formation Evaluation

A Primer on Mind Map, Flowchart and Excel VBA

1. Overview

Engineering analyses usually involves data storage, organization and conversion,


calculation, iteration and representation. With large data sets, these processes can become
complicated if we perform them manually. Therefore, we build software applications to
automate and optimize these processes, but before we can even perform such tasks, we need
to understand the underlying concepts behind each of the processes.
In this course, we will develop skills that will enable us to analyze engineering
problems effectively. Mind Mapping will help us articulate the concepts, flowcharts will aid
us in performing the tasks and Excel Visual Basic for Applications (VBA) will automate and
optimize the processes.

2. Learning Outcomes

Upon successful completion of this module, you will be able to:

• Utilize mind mapping for note-taking and note-making.


• Construct flowcharts to perform tasks.
• Convert flowcharts to Excel VBA syntax.
• Automate processes using Excel VBA.

3. Task

As a formation evaluator, your task for today is to fill-out the required porosity and
permeability data for oolitic limestones from the fictional Sta. Monica Oil-Field (Table 1).

3.1 Required Data

Table 1 Required Porosity and Permeability Data


Porosity (%) Permeability (md)
9
12
50
400
17

1
PetE 31FE Formation Evaluation

3.2 Outputs

To perform the given task, you need to create an Excel VBA tool that estimates the
aforementioned properties through interpolation or extrapolation from the given graph
below (Fig. 1). You also need to provide the following:

a. Mind Map about Linear Interpolation/Extrapolation.


b. Flowchart for Linear Interpolation/Extrapolation.
c. Excel VBA spreadsheet of the project.

Porosity (%)

Figure 1 Permeability vs. Porosity Plot of different sedimentary rocks (Tiab & Donaldson,
2016).

Before you can perform the task, you need to equip and train yourselves first with the
right tools and skills, respectively. You have a week to finish the task. Learn at your own
pace, and have fun learning new stuffs. Let’s

2
PetE 31FE Formation Evaluation

4. Skills

4.1 Mind Map


Here’s a topic about Least Common Denominator (LCD):
“The lowest common denominator or least common denominator is the lowest common
multiple of the denominators of a set of fractions. It simplifies adding, subtracting, and
comparing fractions.” (Wikipedia)

And below are examples of notes taken from the topic (Fig. 2):

a.

b.

Figure 2 Examples of Linear Note-Taking.

Now, as you look at these notes, are you thinking: “Yes! Now I understand what is LCD.
Very inspiring! This will help me in my exams.” If so, good for you, but if you find both of these
notes terrible (aside from my hand-writing), you’re not the only one. Most of us find linear
note-taking tedious and uninspiring. We just copy or write down what we see and hear, then
write it all again the night before hell week because we didn’t remember and understand what
we wrote.

Luckily, there’s a way to have fun while taking-notes. A method that increases your
retention and comprehension, helps you organize and structure concepts and develops your
thinking process. This method is called Mind Mapping.

3
PetE 31FE Formation Evaluation

4.1.a What is Mind Mapping?

Mind mapping is a non-linear method of note-taking and note-making, where ideas


and concepts are structured coherently through radiant patterns (Buzan & Buzan, 1993). The
main idea or concept starts as a central image while the subtopics branch out from the central
image (Fig. 3).

Figure 3 Mind Map about Time Management (Rodrigues, 2011).

4.1.b How to Mind Map

Tools: Drawing materials or mind map applications

General Rules for Mind Mapping:


a. The main idea is always at the center.
b. Branches are always curved lines.
c. Concepts or topics are represented by keywords or statements; all CAPS.
d. Keywords overlie the lines.
e. Use shapes and diagrams.
f. Use a set of colors.

4
PetE 31FE Formation Evaluation

Example Topic:
“The lowest common denominator or least common denominator is the lowest common
multiple of the denominators of a set of fractions. It simplifies adding, subtracting, and
comparing fractions.” (Wikipedia)

Step 1:

- Position the main idea or concept at the center of the paper (Fig. 4).
- Use shapes or images that will help you associate to the idea.

Figure 4 Central Image

Step 2:

- Determine the concepts that can be classified as main branches.


- Draw thicker lines for the main branches.
- Write concepts at the top of the lines.

If we use books as an analogy, then the main idea is the title of a book while the main
branches are the chapters. Identifying the underlying concepts can be quite difficult especially
if you’re taking notes during live discussions. It’s not advisable to write anything anywhere.
You need to be logical in structuring the concepts. You should categorize the concepts from
broad to specific (Fig. 5).

Figure 5 Funnel analogy for categorization of concepts and topics.

5
PetE 31FE Formation Evaluation

Tips:
Instead of writing the concepts as main branches, replace them with:
a. what, why, when, where, how.
b. or use definition, objective or purpose, procedure or method. (I personally use this
one.)

Therefore:

Figure 6 Main Branches

Step 3:

- Connect the subtopics.


- Use thinner lines.

Figure 7 Subtopics

This concludes our note-taking but not our mind mapping. It may not seem obvious,
but learning from note-taking is limited by the one who provided the information. The
information can lack details, accuracy or logical structure, or the presentation is not suitable
to our own way of learning. This is where mind mapping can be helpful. It can further our
learning by converting the taken notes as our own. This is the part where we are making our
own notes through research, validation and elaboration. We can start by asking questions
like what, why and how, and answer these questions through researching, shifting our
perspectives and making analogies.

6
PetE 31FE Formation Evaluation

Step 4:

- Ask questions and add these as branches.


- Elaborate details, specially procedures.
- Add images for analogies or keywords for a different perspective.

Figure 8 Final Mind Map about Least Common Denominator

My mind map may not be creative enough for your taste, but it is enough for me to
understand and present the concept of least common denominator (LCD). The questions are
represented by red fonts and lines (Fig. 8), and a connection between two branches is
represented by a symbol ( ), which is specific to the relationship.

And here’s my thought process:

- I was curious if there are rules or criteria that are necessary before performing the
calculation, so I started from the definition and purpose and reviewed the concept of
multiples and fraction operations, which became the basis for the rules. I also added
detailed illustration (the purple font at the top left).

- Reviewing the fraction operations made me realize that I was only thinking about
operations between two fractions. It did not occur to me that the set of fractions can
be two or more. This also shows that sometimes you can miss the simplest of things.

- I researched about the fastest way to find the least common denominator (LCD), and
it turns out there is a corresponding method for a set of two fractions and another for
a set of three or more.

7
PetE 31FE Formation Evaluation

- I also constructed a more brute method of finding the LCD. This is based on the basic
way of finding the LCD. It is also applicable to a set of two or more fractions.

This concludes the mind mapping. Of course, I can still add more details by making
analogies or by asking who developed the methods, what is the rationale for each of the
methods, are the methods restrictive to their criteria or are there more methods available that
I did not know. As long as you are curious, you can expand your notes and your learning.

4.1.c Effects of Mind Mapping

Mind mapping can improve retention, critical thinking, organization and presentation
(e.g., Buran & Filyukov, 2015; Farrand et al., 2002; Kernan et al., 2017).

4.1.d Mind Mapping Task

It’s your turn to create your own mind maps. I believe that you can organize your
thoughts in creative ways and improve your learning. You can choose your own set of colors
and create rules on its application. You can also use lines or symbols to show relationships
and add images, links, videos or documents if you’re using an application. Always describe
the procedure in detail and use examples or analogies. Just remember, you need to be curious.

You can draw or use a software for your mind map about interpolation/ extrapolation.
You also need to include your thought process just like the example above.

4.2 Flowchart

The next crucial part is developing an algorithm. An algorithm is a procedure that


aids the user and computers on what to do for each of the steps. It describes how processes
must flow from the input data to the output data. You might wonder about the difference
between an algorithm and a normal procedure like the one from the mind map in Fig. 8. If
you look back at the definition of an algorithm, it tells you what to do. The keyword is DO.
There are no steps in algorithms that you need to think, and everything is exact. Of course,
there are exceptions (e.g., randomization), but for most processes, the input is the only step
that requires user intervention.

Now, if you look at the procedure of finding the least common denominator for a set
of two fractions, we see that it starts with finding the greatest common factor (GCF). To us,
this is automatic. We don’t need to think hard about it, but for a computer, it needs a

8
PetE 31FE Formation Evaluation

systematic approach on how to do this. Computers don’t know what to think. We need to tell
them what to do. Therefore, we need to create a procedure, where the only necessary user
intervention is the input, and this can be done using programming concepts (e.g., loops).

Another necessary attribute of an algorithm is its readability and usability.


Algorithms must be logical and concise. Everything must be taken into account, and
therefore, it is necessary to understand the underlying concepts behind the processes. We
need to know the assumptions, criteria, the methods and the required data because these are
the necessary ingredients to construct the flow of processes, which are best visualized using
flowcharts.

4.2.a What is a Flowchart?

A flowchart is a graphic representation of an algorithm. It illustrates the sequence of


processes through shapes and arrows, which represent the steps and flow, respectively (Fig.
9). Table 2 shows the common shapes and their corresponding functions.

Start

“Hello World”

End

Figure 9 Example of a Flowchart

Table 2 Basic Flowchart Shapes and their Functions

Start/ End

Input/ Output

Process (e.g., calculations, sorting)

Conditional Statements

9
PetE 31FE Formation Evaluation

4.2.b How to Create a Flowchart

Tools: Drawing Materials or MS applications

Example:
The brute method for determining the least common denominator (LCD) in Figure
8. (This method is easier to convert into an algorithm.)

Step 1: Create an outline.

- You can use a top-down or bottom-up approach. (Personally, I use the bottom-up.)
- Bottom-up is basically output to input. Start from the output data, which in this case
the LCD, and then determine the necessary processes and input data. (Top-down is
the reverse of bottom-up.)

Bottom-up:

a. Determine the process that will generate the output data and the criteria to
perform the process.

From the procedure:


𝐿𝐶𝐷 = 𝑥𝑖.
Therefore:
Process: Calculation of an equation.
𝑥𝑖 𝑥𝑖 𝑥𝑖
Criteria: 𝐷 & 𝐷 &. . & 𝐷 must be an integer ≥ 1
1 2 𝑛

b. Determine the variables that will start the process.

Variables: 𝑥 and 𝑖

c. Determine the process that will generate the values of 𝑥 and 𝑖 and the criteria
for each variable.

For 𝒙:
Process: Find Largest Denominator among the given denominators
𝐷1 , 𝐷2 , 𝐷3 , … , 𝐷𝑛 .
Criterion: Largest Denominator

For 𝒊:
Process: Loop
Criteria:
- Increment: +1
- Value starts from 1.

10
PetE 31FE Formation Evaluation

d. Repeat step B. If the remaining processes are all user inputs, constants and/or
loop counters (e.g., 𝑖), you are finished.

For 𝑫𝟏 , 𝑫𝟐 , 𝑫𝟑 , … , 𝑫𝒏 :
Process: Input
Criterion: Input the number of denominators.

For 𝒏:
Process: Input
Criterion: 𝑛 > 1

Step 2: Create Flowchart

- Follow the algorithm from Step 1 using also the bottom-up approach.

From the algorithm:

a. Start!

Start

b. Input 𝑛.
Start

c. Check criterion of 𝑛. If it doesn’t pass the criterion, return to input or stop program.

Start

𝑛≥1 No

Yes

11
PetE 31FE Formation Evaluation

d. Input denominators. From the criterion, 𝑛 must be given before the input
denominators. That is the reason why 𝑛 is the first in the flowchart.

Start

𝑛≥1 No

Yes

𝐷1 , 𝐷2 , 𝐷3 , … , 𝐷𝑛

e. Next is the values for 𝑥 and 𝑖. The variable 𝑖 starts from 1 while 𝑥 is determined
from the denominators. Most programs have sorting functions, which makes it
easier to extract the largest or the smallest value from a data set, and therefore, we
don’t need to sort it manually. Also, the value of 𝑥 is not from the user input but
from a sorting process. This is also the same with 𝑖. Its value is defined by the
programmer but not inputted by user.
Start

𝑛≥1 No

Yes

𝐷1 , 𝐷2 , 𝐷3 , … , 𝐷𝑛

𝑖=1
Sort Denominators
𝑥 = 𝑙𝑎𝑟𝑔𝑒𝑠𝑡 𝑑𝑒𝑛𝑜𝑚𝑖𝑛𝑎𝑡𝑜𝑟

12
PetE 31FE Formation Evaluation

f. Calculating the LCD. The criteria must be met first before proceeding to the LCD.
If one of the denominators did not pass, the process loops and repeats with a new
value of 𝑖. Don’t forget to terminate (i.e., End) the flowchart.

Start

𝑛≥1 No

Yes

𝐷1 , 𝐷2 , 𝐷3 , … , 𝐷𝑛

𝑖=1
Sort Denominators
𝑥 = 𝑙𝑎𝑟𝑔𝑒𝑠𝑡 𝑑𝑒𝑛𝑜𝑚𝑖𝑛𝑎𝑡𝑜𝑟

𝑥𝑖 Yes 𝑥𝑖 Yes 𝑥𝑖
= 𝑖𝑛𝑡 ≥ 1 = 𝑖𝑛𝑡 ≥ 1 = 𝑖𝑛𝑡 ≥ 1
𝐷1 𝐷2 𝐷𝑛

No No No Yes

𝑖 =𝑖+1

𝐿𝐶𝐷 = 𝑥𝑖

𝐿𝐶𝐷

End

13
PetE 31FE Formation Evaluation

You can also use the top-down approach like how recipes and procedures are created,
but you must be well-versed about the processes. The bottom-up approach will help you
effectively analyze the methods during the process of creating the algorithm, so even if you’re
still unfamiliar with some steps, using the bottom-up approach will improve your
understanding.

If you carefully observe the example, there are recurring patterns, specially between
the steps and some important programming concepts such as conditional statements and
loops. The criteria serve as the condition for conditional statements while repeating steps or
iterations are converted to loops.

4.2.c How to Check the Flowchart

It is important to test the flowchart to see if it works. The best way to do this is to use
it manually to solve a problem. Try to follow it or map your process and check if it can
generate the correct results given an input data.

Example:
1 1
Find the LCD between 2 and 3.

There are two


denominators. Start
Therefore, input
𝑛 = 2.
𝑛=2

Check 𝑛. Is 2 ≥ 1? Start
If yes, proceed; No,
go back and input
new 𝑛. 2

2≥1 No

Yes

14
PetE 31FE Formation Evaluation

Input
Denominators. Start

2≥1 No

Yes
𝐷1 = 2

𝐷2 = 3

Initiate 𝑖. Find the


largest denominator
Start
and assign it to 𝑥.

2≥1 No

Yes

𝐷1 = 2
𝐷2 = 3

𝑖=1
Sort Denominators (3,2)
𝑥=3

15
PetE 31FE Formation Evaluation

Check criterion for


𝑥𝑖 Start
LCD. If 𝐷 and
1
𝑥𝑖
are integers ≥ 1,
𝐷2
then proceed; else, 2

loop (𝑖 = 𝑖 + 1).

Starting with the 2 No


first denominator, ≥1
𝐷1 : 1.5 is greater
than 1 but not an Yes
integer.
𝐷1 = 2
Therefore: No 𝐷2 = 3

𝑖=1
Sort Denominators (3,2)
𝑥=3

3(1) Yes 𝑥𝑖 Yes 𝑥𝑖


= 𝑖𝑛𝑡 = 𝑖𝑛𝑡
2 𝐷2 𝐷𝑛
= 1.5 ≥ 1 ≥1 ≥1

No No No

𝑖 =𝑖+1

Yes
𝐿𝐶𝐷 = 𝑥𝑖

𝐿𝐶𝐷

End

16
PetE 31FE Formation Evaluation

Loops with a new 𝑖.


𝑖 is now equal to 2.

3(1) Yes 𝑥𝑖 Yes 𝑥𝑖


= 𝑖𝑛𝑡 = 𝑖𝑛𝑡
2 𝐷2 𝐷𝑛
= 1.5 ≥ 1 ≥1 ≥1

No No No

𝑖 =1+1

Yes
𝐿𝐶𝐷 = 𝑥𝑖

𝐿𝐶𝐷

End

Check the criteria


again: 3(2) Yes 𝑥𝑖 Yes 𝑥𝑖
=3 = 𝑖𝑛𝑡 = 𝑖𝑛𝑡
2 𝐷2 𝐷𝑛
3 is an integer and is ≥1 ≥1 ≥1
greater than 1.
Therefore, proceed. No No
No

𝑖 =1+1

Yes
𝐿𝐶𝐷 = 𝑥𝑖

𝐿𝐶𝐷

End

17
PetE 31FE Formation Evaluation

Check the next


denominator:

2 is an integer and Yes 3(2) Yes 𝑥𝑖


3(2)
greater than 1. 2
=3
3
=2
𝐷𝑛
= 𝑖𝑛𝑡
≥1 ≥1 ≥1
Therefore: Proceed
No No No

𝑖 =1+1

Yes
𝐿𝐶𝐷 = 𝑥𝑖

𝐿𝐶𝐷

End

3 is the last
denominator. 3(2) Yes 3(2) Yes 𝑥𝑖
=2 = 𝑖𝑛𝑡
Therefore, we can 2
=3
3 𝐷𝑛
proceed to ≥1 ≥1 ≥1
calculate LCD.
No No No

𝑖 =1+1

Yes
𝐿𝐶𝐷 = (3)(2)

𝐿𝐶𝐷 = 6

End

𝐿𝐶𝐷 = 6; End 𝐿𝐶𝐷 = (3)(2)


Program.

𝐿𝐶𝐷 = 6

End

18
PetE 31FE Formation Evaluation

4.2.d Effects of Creating Flowcharts

Algorithms and flowcharts are not only for computer programs. These are also
beneficial to us as engineers. The least common denominator may be elementary, but as we
peel the underlying concepts, we discovered subtle details that we don’t fully comprehend
before. It can improve the rigorousness of our methods and expose the limits and complexities
of processes. In problem-solving scenarios, it can help us solve things systematically without
thinking too much and can aid us during mind blanks.

4.2.e Flowchart Task

Your interpolation/extrapolation flowchart must include your outline and the


checking or mapping of the flowchart just like the example above. For checking, select one
input from the task data.

4.3 Excel Visual Basic for Applications (VBA)

Congratulations! You’ve learned to articulate concepts using mind maps and perform
procedures using flowcharts, but the flowcharts are still too much for our computer. Some of
the steps requires more elaboration, which can be done through programming concepts (e.g.,
loops).

You are now at the final section and the most exciting part of this training. You will
be integrating your flowcharts with Excel VBA. Let’s

4.3.a Enable Developer Tab

Step 1: Open Excel


Step 2: Click File

19
PetE 31FE Formation Evaluation

Step 3: Click Options

Step 4: Select Customize Ribbon

20
PetE 31FE Formation Evaluation

Step 5: Main Tabs: Check Developer., and then click OK.

Step 6: Check Developer Tab.

Once you’ve enabled the Developer Tab, you don’t need to repeat these steps every
time you open Excel.

21
PetE 31FE Formation Evaluation

4.3.b Where to Write the Code

Step 1: Hit Alt+F11 or


Developer Tab → Visual Basic

A new window will appear: The Visual Basic Editor (VBE) Window.

22
PetE 31FE Formation Evaluation

Step 2: Right-Click anywhere on the Project Window

Step 3: Select Insert

There are three options: Userform, Module and Class Module. We will write most of
our codes in the Module.

23
PetE 31FE Formation Evaluation

Step 4: Select Module among the three options (i.e., Userform, Module, Class Module).

Module 1 is created, and its corresponding code window is opened. We can also
rename Module 1 at the Properties Window or by Right-clicking Module 1 under the Module
Folder. The Code Window is where we will write our VBA syntax. We can create a lot of
modules for different processes, but it’s more ergonomic to put all our codes in one module.

4.3.c Writing your First VBA Syntax

Step 1: Pre-syntax
Before writing our main syntax, let’s write two important codes at the top of the code
window. First is Option Explicit. We can write it manually or enable it at the Toolbar →
Tools → Options → Editor Tab → Check Require Variable Declaration. If you do the latter,
every time you create a new module, the code is automatically written at the top. What this
code does is it prompts Excel to require us to declare all of the variables. Therefore, if a code
contains a variable that was not declared, Excel will prompt us with an error window. Last is
the Option Base 1. This is for indexing of arrays, so that the index starts at 1 instead of the
default value, which is 0. You will understand the rationale for this code in the succeeding
sections.

24
PetE 31FE Formation Evaluation

Step 2: Creating your first Sub Procedure


Procedures in Excel VBA are classified into two: Function procedures and Sub
procedures. A Function procedure acts similar to a mathematical function. You input the data
into the function, and then it generates output data. The SUM function in Excel is an example
of a Function procedure. A Sub procedure can perform actions or processes but can’t return a
value unlike a Function procedure. There are some key differences between the two types of
procedure, but it’s not important for our purpose right now.

Write the name of your Sub procedure: Sub Name() (Note: No spaces in the name part.). Then
hit enter. It will automatically enclose the procedure with End Sub. You will write the code
inside the Sub procedure.

Step 3: Declare your variables


In programming, variables are classified based on data types. Integers and decimals
are classified as int or long and float or double, respectively. Texts are classified as string.
Another one is the variant data type, which can hold almost all types of data. This means it
can contain strings, integers or decimals. There are a lot of data types, but these are the
common ones. (Note: long and double are commonly used for integers and decimals,
respectively.)

Dim statements are used to declare variables in VBA. You only need to use it once per
line and not per variable.

From the example exercise, there are 5 variables based on the flowchart:

Note: Comments are preceded by an apostrophe.

25
PetE 31FE Formation Evaluation

All of the variables are integers because denominators are always integers. I usually
arrange my variables based on data types and separate variables that are used as loop counters
(e.g., 𝑖). For the denominators, there quantity is based on 𝑛 and is not fixed. Therefore, we
need to use a type of variable that can accommodate this – dynamic arrays. Arrays are
variables that can store a set of data in a matrix. Matrices are usually 1D or 2D and rarely
more than two dimensions. A spreadsheet typifies a matrix. We can envisage a 1D array and
2D array as a row with multiple columns and multiple rows with multiple columns,
respectively. There are two types of arrays: static arrays, which have fixed dimensions and
dynamic arrays, which have varying dimensions.

To declare a static array, you need to define its dimensions: (Option Base 1 is enabled.)

ID code 1 code 2
1 as1 qw1
2 as2 qw2
3 as3 qw3

Example Data for arr_static (Note: The headers are not included).

The example above is a 2D array that contains values with different data types.
Therefore, the array is declared as variant to accommodate all of the different types of data.
The first dimension defines the upper boundary of the index for rows (e.g., 3), and the second
dimension defines the upper boundary of the index for columns (e.g., 3). Remember the code:
Option Base 1? If this code is omitted, the index will start at zero. This means that row or
column 1 is index 0, row or column 2 is 1 and so on. Therefore, if Option Base 1 is disabled
and arr_static has 3 rows and 3 columns, the declaration should be:

The indices are like coordinates of a datum. Therefore, arr_static(0,0) is 1,


arr_static(0,2) is qw1, arr_static(2,2) is qw3 and so on. If Option Base 1 is enabled, the index
will start at 1, the index will also correspond to the row or column number and the upper
boundary will also correspond to the number of rows or columns. Therefore, arr_static(1,1)
is 1, arr_static(1,3) is qw1, arr_static(3,3) is qw3 and so on.

For 1D array: The data is arranged or listed in a row.

Color red orange yellow

26
PetE 31FE Formation Evaluation

But it’s more beneficial to use the syntax for 2D arrays even if the data is 1D:

Color red orange yellow

Or

Color
red
orange
yellow

In this case, the data are contained in a 2D array even though the data is a 1D list.
You can choose how your data can be arranged unlike in the case of 1D arrays. Another
advantage is you can directly copy or paste values from or to spreadsheets, respectively, in
the same format or arrangement. We will build more intuition on arrays in the succeeding
modules.

If the dimensions of an array are initially unknown and are only characterized during
a process or after an input, then we can declare the arrays with no dimensions just like with
our example for least common denominator. The variable arr_D, which will contain the
denominators, is declared with no dimensions. This variable will be re-dimensioned after
inputting 𝑛. Dynamic arrays can always be re-dimensioned anywhere after the initial
declaration using the Redim statement. For example:

There are still a lot to cover on arrays, but we will stop the discussion here and proceed
to the next part.

Step 4: Follow the flowchart


There are may ways to take an input for Excel VBA, but for our example, we will use
the input box. The input box has arguments from the prompt message to its buttons, but
most of the time we are only interested in the prompt message.

27
PetE 31FE Formation Evaluation

The input from an input box is taken as a string, but we can convert it to a number
using the Val function. As you can see below, the input box is assigned to 𝑛. Therefore, 𝑛 will
get its value from the input on the input box.

You can test this code by pressing F5 or by clicking the play button at the tool bar.

If you play the code, an input box will appear, where you will place the input.

Next, we need to check the criterion for 𝑛:

28
PetE 31FE Formation Evaluation

Instead of going back to the input if the criterion is not met, I changed it to
termination of the program. Now, there are ways to do this, but let’s use the conditional
statement for now. Therefore, if the criterion is not met, the program will not proceed to
whatever code that will be within the if-statement and will proceed to the next line, which is
the End Sub (termination). This syntax works because there are no lines after the if-statement
except the termination line. Take note of the format of the if-statement.

From the LCD flowchart, if the criterion for 𝑛 is met, the next process is to input the
denominators, but as we now know, we need to re-dimension the arr_D before we can input
any values. Therefore:

We can now input denominators, but how? In this case, we’ll use a loop, so let’s add
a new loop counter, 𝑎.

29
PetE 31FE Formation Evaluation

Loops are always partnered with arrays, especially in populating the arrays with
values. There are many types of loops in VBA (e.g., Do-While, Do-Until), but most of the
time a For-Next loop will suffice. If we look at the format, the loop counter succeeds the For
statement together with its initial value and the final value (e.g., 1 to 𝑛). This also means that
the process will loop only if 1 ≤ 𝑎 ≤ 5. The Next statement increases 𝑎 by 1 before repeating
the process.

To populate arr_D, we will use input boxes:

(Note: The ampersand, &, are used to concatenates texts with other texts or numbers.)

Next, we will sort the denominators using the sorting tool in Excel. First, we need to
paste arr_D on the spreadsheet, but before we can access the parts of Excel, we need to
understand first the concept of object hierarchy.

Components in Excel (and even Excel itself) are classified as objects, and these objects
have properties, which can be read-only or read-write. Before we can access and toggle these
properties, we need to follow VBA’s object hierarchy. We can liken this system to a cabinet
with many compartments. If we use this analogy, the cabinet represents Excel. And inside it,
there are workbook compartments. We can think of it as the main compartments of the Excel
cabinet, and these workbook compartments are called the Workbooks Collection. If we want
to access a particular workbook, we need to open the Excel cabinet, and then access the
selected workbook compartment among the collections. The syntax for this is:

30
PetE 31FE Formation Evaluation

The application represents Excel, and within it, there is a Workbooks Collection.
Among the Workbooks Collection, there is a workbook called Book1.xlsx. (Note: Collections
are always plural.)

Let’s continue our cabinet analogy. Each of the workbook compartments has their
own Sheets Collection, and there are two types of sheet collections: Worksheets Collection
and Charts Collection (i.e., Chart Sheets). Let’s focus on worksheets for now. Each of the
worksheets has cells within it. These group of cells are called Range, and each of the cells has
a Value Property that we can read and write. Therefore, if we want to know the value of cell
A1 from Sheet1 inside Book1, we need to write the following:

(Note: Sheet1 and Book1 are names of a worksheet and workbook. Therefore, if the name of
your worksheet and workbook are “LCD” and “FormEval”, respectively, use these names
instead, and don’t forget the quotations.)

We can shorten this syntax into the line below if our codes only need to manipulate
the objects inside the workbook that we are working on.

Going back to our LCD example, we need to paste the values of the arr_D in the
spreadsheet. We will paste arr_D in column A starting from cell A1 inside Sheet1. The
column format is based on the format of arr_D, which is in column format. Let’s start by
clearing the values of column A whether it has values or not. To clear the values, we will use
the Clear Method. Methods of an object perform actions. Therefore: (Range(“A:A”) defines
the column A.)

Next, we write data to column A:

If 𝑛 = 3, then Range(“A1:A” & 𝑛) becomes Range(“A1:A3”). As we can see, a range


can contain columns, rows or any group of cells.

31
PetE 31FE Formation Evaluation

Next, sort from largest to smallest:

(Note: Underscores are used to indicate that the code continues to the next line.)

The syntax for sorting contains a lot of arguments. Let’s just look at the important
ones and leave the others to their default values. The first line clears any sorting that was
applied to the data. The second line is where the sorting is enabled. The Key defines the
location of the data or table and the Order defines the order format (i.e., descending or
ascending). The next line is the SetRange, which also defines the range of the data. Next is
the Header argument, which has a default value of xlNo. Since our set of data has no header,
we’ll leave it to its default value. The last important line is the Apply.

There’s no need to memorize this syntax or any complicated syntax in VBA. You can
just search it in the web. The important thing is knowing the arguments.

If you’ve observed the syntax for sorting, there is one recurring statement,
Worksheets(“Sheet1”).Sort. We can use the With-statement to shorten the syntax:

32
PetE 31FE Formation Evaluation

Based on the sorting, the largest denominator will always be located at cell A1.
Therefore, 𝑥 will be equivalent to the value of cell A1.

Next, check 𝑥𝑖 criteria: (We’ll use a Do-Until loop together with a For-Next loop.)

(Note: Don’t forget to write the operation. 𝑥 ∗ 𝑖 not 𝑥𝑖)

As you can see, we have a nested loop, and 𝑖 is initiated before the Do-Until loop. Also,
remember that 𝑥𝑖 must be check for all denominators, which are stored in an array. To check
for each of the values in the array, we need to use the For-Next loop. The For-Next loop can’t
be used for 𝑖 since this type of loop requires a maximum value for its counter, which we can’t
define for 𝑖. Therefore, the Do-Until loop is necessary to execute the loop. The Do-Until loop
will iterate until the criteria are met.

𝑥𝑖 𝑥𝑖
There are two criteria for 𝑥𝑖: first is 𝐷 ≥ 1 and second is 𝐷 = 𝑖𝑛𝑡𝑒𝑔𝑒𝑟. Therefore, if
you look at the If-statement within the For-Next loop, there are two conditions that represent
the criteria and are linked by And, which denotes that both criteria must be met. The Int
function converts the number to an integer. If the original value divided by the converted
value is equal to one, then the number is divided by itself and is an integer. The 𝑐 is a counter
to check if the criteria were met 𝑛 times and is also used as the condition for the Do-Until
loop. Its value is reset for every iteration in the Do-Until loop. The next If-statement checks
if 𝑐 is equal to 𝑛. If 𝑐 = 𝑛, then 𝑥𝑖 is assigned to 𝐿𝐶𝐷 and the Do-Until loop is stopped.

The last step is to show the output data. This can be done by pasting the output to a
cell or range of cells or by showing it through a message box.

33
PetE 31FE Formation Evaluation

The former method: writing the value to a cell, say B1

The latter method: using a message box

The syntax is MsgBox then followed by a text or any value that you want to show.

Step 5: How to integrate the Sub procedure with the worksheet


a. Go to Developer Tab

b. Click Insert

c. Under Form Controls, select Button Form Control

34
PetE 31FE Formation Evaluation

d. Draw a button anywhere on the worksheet

e. A pop-up will appear, and under it are your Sub procedures or macros. Select the
desired procedure, which in this case is the Find_LCD procedure, and click OK.

f. A button will appear. You can rename and resize it. To use the button, click anywhere
to exit from the edit mode, and then click the button, and it will execute the procedure
for you.

35
PetE 31FE Formation Evaluation

g. Save your workbook as Excel Macro-Enabled Workbook.

The VBA program for finding the least common denominator is now finished, but of
course we can still make it more error-proof such as including a set of criteria (e.g., no zero
values, decimals or letters) for the denominators or for 𝑛. The elaboration of some of the steps
where mostly done by using loops, conditional statements, arrays or other Excel functions,
and it is difficult to use these concepts without a flowchart. Therefore, you need to create a
flowchart before converting it to codes.

If you want to further your skills in Excel VBA, you can read Excel VBA for Dummies
by Alexander & Walkenbach (2019).

4.3.d Flowchart Exercise


In the example, I did not show the final flowchart that was used to create the syntax,
and I want you to reverse engineer the flowchart from the syntax.
a. Illustrate the final flowchart that was used to create the syntax for the Find_LCD
procedure.
b. Elaborate and modify your flowchart for interpolation/extrapolation.

4.3.e VBA Task


Incorporate your finalized flowchart with Excel VBA. There must be a worksheet inside
your workbook that contains the required data for the task.

5. References

Alexander, M., & Walkenbach, J. (2019). Excel VBA Programming for Dummies (5th ed.).

Buran, A., & Filyukov, A. (2015). Mind Mapping Technique in Language Learning. Procedia - Social
and Behavioral Sciences(206), 215-218.

Buzan, T. (1988). Super-Creativity: An Interactive Guidebook.

Buzan, T., & Buzan , B. (1993). The Mind Map Book: How to Use Radiant Thinking to Maximize your
Brain's Untapped Potential.

36
PetE 31FE Formation Evaluation

Farrand, P., Hussain, F., & Hennessy, E. (2002). The Efficacy Of The ‘Mind Map’ Study Technique.
Medical Education(36), 426-431.

Kernan, W., Basch, C., & Cadorett, V. (2017). Using Mind Mapping to Identify Research Topics: A
Lesson for Teaching Research Methods. Society for Public.

Rodrigues, J. (2011, August 31). Everything You Need To Know About Mind Mapping. Retrieved from
Iris: Speed Reading Classes, Memory & Productivity Courses:
https://irisreading.com/mindmap/

Tiab, D., & Donaldson, E. C. (2016). Petrophysics: Theory and Practice of Measuring Reservoir Rock
and Fluid Transport Properties (4th ed.).

37

Das könnte Ihnen auch gefallen