简体   繁体   中英

How to calculate average of row based on input in another cell

I was wondering if you can show me a little trick here in Excel. I have a row here in Excel that is 25 columns wide as shown below.

What I want to be able to do here, is to calculate the average tonnage or kW annually. However I want to be able to input a number for the amount of years and for it to calculate that.

So in the image right now I have it set to calculate the average for 25 years. But let's say I want to average it for 20 years instead, so that I can input 20 into the years cell, and have the yearly average show up for the years of 1-20, rather than 1-25.

My macro skills aren't too sharp so any help is appreciated!

Use something like this:

=AVERAGE(C3:INDEX(C3:Q3,1,$C$11))
  • where C3 - first cell of row with data
  • C3:Q3 address of entire row
  • C11 contains number of years to count (eg 10 or 20)

在此处输入图片说明

You don't need VBA for this. Try this formula out:
=IFERROR(AVERAGE(OFFSET(A1,0,0,1,A2)),"")
Where A1 contains the first data and A2 contains the number of years you want calculated.
Enter the formula in the Yearly Average column.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM