Totaling only Visable Cells Excel 2007

I heart Excel

Board Regular
Joined
Feb 28, 2011
Messages
66
Hello,

Hope everyone had a nice a weekend!!

I am trying to sum only the visible cells on my spreadsheet.

I have had a look and tried two ways -

Way 1 =

Function VisTotal(Rg as Range)
dim x, tot
Application.Volatile
tot=0
For each x in Rg
if c.visible then tot=tot+x
Next
End Function


in Worksheet -
=VisTotal(E54,E49,E47,E39,E34,E32,E24,E19,E17)

Way 2 =

<CODE>
Function Sum_Visible_Cells(Cells_To_Sum As Object) Application.Volatile For Each cell In Cells_To_Sum If cell.Rows.Hidden = False Then If cell.Columns.Hidden = False Then total = total + cell.Value End If End If Next Sum_Visible_Cells = total End Function </PRE>
In worksheet - =Sum_Visible_Cells(E54,E49,E47,E39,E34,E32,E24,E19,E17)

On both I get a #NAME? error?! And I can't figure out why.

thanks


</CODE>
</PRE>

 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I just tried your Sum_Visible_Cells and it worked fine ( with carriage returns in there, no as one long line like you have ).

Can you explain where you are putting the code?
 
Upvote 0
Why not just use SUBTOTAL(109,range)?
 
Upvote 0
I did the subtotal and this worked great, thanks!!

I was putting the sum at the bottom, tried it again, but still got the error must've been doing something wrong!! I was putting the code on the VBA sheet, should it of been the workbook?!

Thanks for your help
 
Upvote 0
Your code should have gone into an ordinary Module ( Insert / Module ).
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,750
Members
452,940
Latest member
rootytrip

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