Is it possible to run averages on a userform?

MFish

Board Regular
Joined
May 9, 2019
Messages
76
Hi,

Is it possible to calculate averages on a userform with TextBoxes/Comboboxes?
Example:

Code:
Combobox1.additem = "50%"
Code:
combobox2.additem = "100%"
Maybe...? Lol
Code:
Textbox1.value = combobox1.average + combobox2.average

Visually it would say within Textbox1
75%

So, before I hit submit on the userform and put it down on cells A1-A3, I can see the calculation.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hi,

Is it possible to calculate averages on a userform with TextBoxes/Comboboxes?
Example:

Code:
Combobox1.additem = "50%"
Code:
combobox2.additem = "100%"
Maybe...? Lol
Code:
Textbox1.value = combobox1.average + combobox2.average

Visually it would say within Textbox1
75%

So, before I hit submit on the userform and put it down on cells A1-A3, I can see the calculation.


Ok, I figured out something...

I can use, let's say, 3 textboxes...

Textbox3 is the one I want to show the average of the other 2 inputs. Code goes:

Code:
Sub textbox3_Change()

textbox3.value = (Textbox1.value + Textbox2.value) /2

End Sub

If I type in 10 in textbox1 and 6 in textbox2, I should get a value returned back in textbox3 as 8, but it doesn't. Why?
 
Upvote 0
Try with this
Code:
Sub textbox1_Change()
textbox3.value = (Textbox1.value + Textbox2.value) /2
End Sub

Sub textbox2_Change()
textbox3.value = (Textbox1.value + Textbox2.value) /2
End Sub
 
Upvote 0
This works better... But, issue with the value returning in Textbox3 is it's taking the individual number from textbox1 and textbox2, respectively and dividing it by 2. It doesn't add the two together and THEN take the average.
If textbox1 is 10 and textbox2 is 20 the value it returns in textbox3 is literally, 510... "5 from the 10 divided by 2" and "10 from the 20 divided by 2".
 
Upvote 0
This works better... But, issue with the value returning in Textbox3 is it's taking the individual number from textbox1 and textbox2, respectively and dividing it by 2. It doesn't add the two together and THEN take the average.
If textbox1 is 10 and textbox2 is 20 the value it returns in textbox3 is literally, 510... "5 from the 10 divided by 2" and "10 from the 20 divided by 2".
Code:
textbox3.value = (val(Textbox1.value) + val(Textbox2.value)) /2
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top