Macro help to calculate the median

habercio

New Member
Joined
Jan 25, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi, im trying to create a macro that enables me to calculate the median of any sequence of numbers provided by the user when the sum of these numbers is> 1000 or the average if this condition is not met. This is one of my first contacts with VB, so I got stuck almost at the beginning, I will be grateful for each tip.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
What about using excel MEDIAN function
you can do it with an equation:
=IF(SUM(E3:E34)>1000,MEDIAN(E3:E34), AVERAGE(E3:E34))

first tip for VBA don't use it unless you have to
 
Upvote 0
Solution
You're right that it would be much easier but in this case I'm actually forced to do this via VBA, because it's a a part of my task from excel classes.
 
Upvote 0
I suggest that your first comment in class is my first tip!!
So your requirement is that you must use VBA, so does your requirement prohibit you from using EXCEL functions? OR is this not specified??
 
Upvote 0
It was not specified whether it's forbidden to use Excel functions or not so I recorded the macro without using VBA, using the formula you wrote. Everything looks like it worked out, I hope it will work for my professor as well. Sometimes the simplest solutions are the best. Thank you very much for your help, all the best.
 
Upvote 0

Forum statistics

Threads
1,223,956
Messages
6,175,609
Members
452,660
Latest member
Zatman

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