Homework09 Assignment
Homework09 Assignment
1. The Problem 1 worksheet in the Excel template contains a button that displays a blank user form.
The objective of this problem is to enhance that user form so it converts metric units to English units. In
the end, your user form should look exactly like the picture below. The three conversions that your
converter should do are: 1 cm = 0.3937 inches, 1 hectare = 2.471 acres, and 1 liter = 0.2642 gallons. The
user types in the quantity that they want to convert in the top box, then they select the conversion using
the combo box, and the result appears instantly in the bottom box.
(a) Start by placing all of items on the blank user form. Format the items and resize the user form as
needed. The user form caption should be “Metric Converter,” the labels should all be 10 pt, and the
labels should all be centered. Also, the bottom textbox should be “Locked” so that the user cannot
type in it. Note: We could have used either a label or a locked textbox for the output of the
converter. The advantage of the locked textbox is that you can select the value in the textbox, copy
it (Ctrl+C), and then after you close the userform you can paste the value into a spreadsheet cell.
(b) Next, we need to specify the values to display in the combo box when the user form opens. Create a
macro that runs when the user form is opened as described in the user form lecture. In this macro,
write the following code:
With ComboBox1
End With
Note: If your ComboBox is not named ComboBox1, you will need to use its correct name in the first
line of this code.
(c) In the VBA user form editor, double-click on the top textbox (I’ll assume this is called TextBox1).
Double-clicking should create a macro called something like “TextBox1_Change.” This macro will be
run whenever the user changes the data in the textbox. Make this macro do the following:
2. Check whether usable data has been entered by the user. You can do this with a statement like:
“If IsNumeric(InValue) then” where the IsNumeric function is true if the variable is numeric and
false if it is text or blank.
3. If the value is numeric, then make the macro implement whichever conversion has been specified
in the ComboBox. For example,
Else If …
Else …
End If
where the … parts are for you to fill in. Note: this code assumes that the ComboBox is named
ComboBox1 and the Textbox where the results should be placed is called TextBox2.
(d) In the VBA user form editor, double-click on the combo box. Double-clicking should create a macro
called “ComboBox1_Change” if the combo box is named ComboBox1. Make this macro identical to
the one you created in part (c) because we want to try to calculate the unit conversion if either the
text box or the combo box has been changed by the user.
(e) Test your user form to be sure it is working and copy a converted value from the user form and
paste it into a spreadsheet cell.
(f) The disadvantage of our current user form is that once you copy a value from the output textbox
you must close the user form so that you can access the spreadsheet to paste the copied value into
a cell. Module1 in the homework template contains the following macro to display the user form:
Sub ShowForm()
UserForm1.Show
End Sub
This will allow you to go to the spreadsheet while the user form is displayed. Try this and see if you
can convert a number of values and write them to the spreadsheet before you close the form.
2. The Problem 2 worksheet contains data representing the topographic profile of a bedrock landscape
near Lake Tahoe, California, which was covered by hundreds of meters of ice during the last glacial
maximum.
(a) Make a plot of the data, with distance on the horizontal axis and bedrock elevation on the vertical
axis. Place the plot in the specified area on the worksheet.
(b) Use the SLOPE and INTERCEPT functions to fit a line to the data using linear regression. Report the
slope and intercept in the indicated answer cells on the worksheet.
(c) Create a new column of the predicted bedrock elevation values for each distance value using your
slope and intercept from the linear regression, and add this line to your plot. Include a legend on the
plot indicating which line is the original data and which is the linear fit.
(d) Compute the sum of squared errors (SSE), total sum of squares (SST), and coefficient of
determination (r-squared) for your regression fit, and report these values in the appropriate cells on
the worksheet.