VBA code to average last 6 columns in a row

J1149

New Member
Joined
Jan 20, 2007
Messages
39
I have a spreadsheet with 52 columns (weekly sales to date)of data. I need to average the sales for last six columns with data in a row. Anyone who can help with this?

Thanks in advance
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
You could use a formula for this.
As an example I have headings down column A, and data from B to P, with some of the end columns cleared out. Therefore each row has data in every cell to the last one, no gaps, and then blank cells.
The formula is in T2. filled down.

First: create a dynamic named range.
Select B2:G2 and create a range called LastSix.
Go to the Name Manager (Insert > Name > Define for 2003-, or Formulas > Name Manager for 2007+)
Select LastSix and replace the reference with this formula:
Code:
=OFFSET(Sheet1!$B14,0,COUNTA(Sheet1!$B14:$P14)-6,1,6)
OK to accept the defnition, then close the dialog.

In T2, the formula is =AVERAGE(LastSix)

Note: Adjust references to handle the 52 columns of data.

This part of the formula is where you define the start point of hte last 6 columns. Adjust to suit:
COUNTA(Sheet1!$B14:$P14)-6

Denis
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,509
Messages
6,179,192
Members
452,893
Latest member
denay

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