Académique Documents
Professionnel Documents
Culture Documents
Introduction
Formulas are very important in solving chemical engineering problems. However, some of these formulas
are too long and are weary-some to input into a computer program repeatedly. This lecture will guide the
students on how to input long formulas in excel as a function. It also includes topics on how to determine
equations from tabular data.
Creating a Function
As an example consider the formula for determining the vapor pressure of liquid water as a function of
temperature taken from the Handbook (Section 12 page 12-5),
−6096.9385
ln(𝑝𝑠 ) = + 21.2409642 − (2.711193 𝑥 10−2 𝑇) + (1.673952 𝑥 10−5 𝑇 2 ) + 2.433502ln(𝑇)
𝑇
where ps is in Pascal and T in Kelvin. Following steps1 to 8, the output is shown in figure 2. Note that “ps” is
the function name and “T_K” is the required input variable. Choosing how to represent the “function name”
and the “required variable” is discretion of the student. You should choose representation in a way that you
can easily recall the function and what is needed by the function. For example, I choose “T_K” as the
required input because it will remind me that the required input is temperature “T” and it should be in Kelvin
“K”. It is also notable that the equivalent of “ln” in VBA is “log”. Another way of writing the above equation is
shown in figure 3.
On figure 3, it can be observed that the input variable is in Celsius “C”. Since the formula requires
temperature in Kelvin, the input “T_C” must be converted to Kelvin. Conversion is shown in line 3. Note
also of the color of the lines. Blue colored-lines denote the main operation you are going to perform, either
“Sub routine” or “Function”. Black colored-lines are the executable codes while the green colored-lines are
comments. Comments will be ignored during the execution of the code. It is good to integrate comments
into a code because it will help you recall what are those lines for.
How are you going to use the function? Well, just go to your spreadsheet and click the cell you want to
input your function. Input “=” then the name of the function and the required input value, press enter.
Example on how to use the vapor pressure function is shown in the figure 4 and 5.
To permanently saved a function, saved the Excel file as an “Excel Macro-Enabled Workbook” as shown in
figure 6.
Classroom Activity