Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2008

Tip: Looking for answers? Try searching our database.

Sum Visible Cells Only

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tiger - 23 Jan 2008 05:28 GMT
I have created a structured spreadsheet (not filterable) for reporting of
various sales by industry.  I have also added macros which displays only rows
related to specific industry groups.  To ensure the totals sum only the
visible cells I have added the attached function code to the spreadsheet
which I sourced from the Microsoft resources and another site;

Function Sum_Visible(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 = total
End Function

The function works fine as long as the except that the total it provides is
based on the cells referred to in the function but on the active worksheet.  
So for example if the function is used in sheet 2 and sheet 3 but
application.calculate is run while in sheet 1,  the functions sums the
relevant cells selected on sheet1.

The only other relevant thing is that the function is applied to a
non-continguous range,  if that makes any difference.

I have created a workaround by forcing application.calculate each time a
sheet is selected.  It's a little sloppy but at least the function is working.

Any assistance would be greatly appreciated.
Gary Keramidas - 23 Jan 2008 05:38 GMT
you could use this formula, and even write code using it if you have excel 2003

=subtotal(109,a1:a10)

Signature

Gary

>I have created a structured spreadsheet (not filterable) for reporting of
> various sales by industry.  I have also added macros which displays only rows
[quoted text clipped - 27 lines]
>
> Any assistance would be greatly appreciated.
Tiger - 23 Jan 2008 06:35 GMT
Gary,

Thanks for the tip .... I guess it pays to look at the help more regularly.

> you could use this formula, and even write code using it if you have excel 2003
>
[quoted text clipped - 31 lines]
> >
> > Any assistance would be greatly appreciated.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.