Caculate the average value of a range

tulalit

New Member
Joined
Jul 19, 2011
Messages
4
Hi guys. I need your help.
I need to calculate the average value of a range consisting of several cells. If among the cells in a range that contains blank, I want to write "BL" as a result, if not I will certainly write down the value of the real average of the numbers that exist within that range. thanks
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
This VBA code works a little differently than that formula. It is going to check and see if there are the same amount of numbers in the range as there are cells in the range. I am using Range("A1:A5") in this example.

Code:
Sub test()
Dim c As Range, d As Long
Set c = Range("A1:B5")
d = Application.WorksheetFunction.Count(c)
If d = c.Cells.Count Then
    Range("A6") = Application.WorksheetFunction.Average(c)
Else
    Range("A6") = "BL"
End If
End Sub
 
Last edited:
Upvote 0
You can just use the worksheet functions. Which range do you want to operate on and where should the result go? Or do you want a User Defined Function?
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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