Calculations in A Userform - Excel VBA
Calculations in A Userform - Excel VBA
Calculations in A Userform - Excel VBA
Contents [show]
In this tutorial I’ll be showing you how to perform multiple calculations in a Userform. We will be using formulas in a
worksheet to do the major work for us. I have used this process successfully in larger applications where multiple
calculations need to be performed in the Userform before the data is sent to the dataset.
This video is designed to help you understand how the application will work. It will also give you step-by-step
instructions on creating the Userform and where you should add the code that you will find below.
1
that will get you started with dynamic named ranges?
Dynamic Named Range Tutorial
Adding the named ranges
You should call the named range “Products”
=Sheet1!$I$5:$I$20
2
Make sure that you have watched the video and create the Userform as shown in the illustration above. Notice the
names for the textboxes and command buttons and combobox.
You will need to use these exact names for the code that you will be later adding to the Userform to work.
This Userform thus consists of
7 labels
5 text boxes
2 command buttons
1 ComboBox
3
In the Properties for the ComboBox click into Rowsource and add the name for the named range that you created
earlier “Products”
'When the combo box value changes we need to clear all the other values
4
.txtKg.Value = ""
.txtPercent.Value = ""
.txtMarkup.Value = ""
.txtTotal.Value = ""
End With
End Sub
'This is the code that sends the values to the worksheet and then reassigns them back into the userform
Sub Showme()
frmProducts.Show
End Sub
In conclusion
I hope you have enjoyed this tutorial to show how you can do calculations in a Userform quite simply. There are two
more tutorials to come were I will demonstrate creating a Bonus Calculator for employees and an Age and BMI
Calculator in Userforms.
Best wishes
Trevor