Average of a dynamic range (starting from the4 bottom!)

Ealglez

New Member
Joined
Mar 13, 2015
Messages
28
Dear All,

I am new in VBA and I would like to do the following for my master w/s: I have a trend of time vs. variable XD (the length of this trend will vary - can be a total time of 15 hours, 20 hrs, 5hours etc. with variable intervals as well).

I would like to calculate the average of the variable XD Only for the last 2 hours of the trend, i.e. if the trend if from 0 to 15 hours, I would like to calculate the average of XD from t = 13 hours to t = 15 hours. For case 1, trend data is in A6:B102 (headers in A6:B6).

As mentioned above, this trend will change for each case I have and therefore a definition of a dynamic range is necessary ( I guess!). My logic is to create a macro able to count until the last row, read the time in column A (15 hours in the example), locate the row Ax with time (15-2) hours and then average the corresponding values in Bx:B102 cells. Alos, please not that time should be rounded to the 2nd decimal (ex. t = 15.00032 and t= 13.000456 in trend data).

Thank you very much!
E
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi,

If you use a Table (Menu: Insert-->Table) that will take care of the dynamic bit. The table will expand as data is added.

I put some data labelled "a" and "b" in the first two columns then converted it to a table (called Table1 by default).

My formula became: =AVERAGEIF(Table1[a],">="&(MAX(Table1[a])-2),Table1)
 
Upvote 0

Forum statistics

Threads
1,215,426
Messages
6,124,829
Members
449,190
Latest member
rscraig11

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