remove 0s after cells

Rammy

New Member
Joined
Feb 17, 2011
Messages
11
Hi All,

I need an Excel function (or VBA code) that will average including first 0's and only including 1 of that last 0s. For instance,

0
0
2
0
4
0
0
0

Would average out to 1, since (0+0+2+0+4+0)/6 = 1.
The problem is there may be multiple zeros between two positive numbers.
Honestly, I have thought about this for sometime (and started a similar thread for a related problem), but I haven't had much luck.

Any help would be fantastic!

Thanks!

p.s. I am using Excel 2003.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
If your data starts in cell A1 and goes down column A, then try this...
Code:
=AVERAGE(INDIRECT("A1:A"&SUMPRODUCT(MAX((ROW(A1:A1000))*(A1:A1000<>0)))+1))
 
Upvote 0
It works perfectly for what I asked, but I need to be able to drag the formula
horizontally (indirect doesn't seem to like the quotes).

Thank you very much!
 
Upvote 0
Hi All,

I need an Excel function (or VBA code) that will average including first 0's and only including 1 of that last 0s. For instance,

0
0
2
0
4
0
0
0

Would average out to 1, since (0+0+2+0+4+0)/6 = 1.
The problem is there may be multiple zeros between two positive numbers.
Honestly, I have thought about this for sometime (and started a similar thread for a related problem), but I haven't had much luck.

Any help would be fantastic!

Thanks!

p.s. I am using Excel 2003.

Looks like...

Control+shift+enter, not just enter:

=AVERAGE(A1:INDEX(A1:A8,MIN(ROWS(A1:A8),MATCH(9.99999999999999E+307,1/A1:A8)+1)))
 
Upvote 0
The last one worked perfectly, and I hate ask again, but I need the same function to work on rows (I would tranpose, but there are too many rows to fill up the columns).
 
Upvote 0
The last one worked perfectly, and I hate ask again, but I need the same function to work on rows (I would tranpose, but there are too many rows to fill up the columns).

I guess you want it row-wise (horizontal)...

Control+shift+enter, not just enter:

=AVERAGE(A1:INDEX(A1:F1,MIN(COLUMNS(A1:F1),MATCH(9.99999999999999E+307,1/A1:F1)+1)))
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,733
Members
452,939
Latest member
WCrawford

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