+ Reply to Thread
Results 1 to 23 of 23

Sumif only visible cells

  1. #1
    Registered User
    Join Date
    07-27-2015
    Location
    England
    MS-Off Ver
    Office 2010
    Posts
    40

    Sumif only visible cells

    Hello

    I’ve been having some trouble in terms of using sumif only on the visible cells.
    My data is currently laid out as follows:

    Excel.PNG

    What I'm trying to do is:
    1) Filter column A so that only the blank cells are visible...

    Excel1.PNG

    2) Once the list has been filtered i need to use a sumif on the filtered range only & ensure that the value is populated in column A.
    3) Any zero values in column A should lead onto the corresponding rows being deleted.



    Unfortunately my formula carries out the sumif for everything in a range regardless of whether or not it is filtered.
    This is just an extract of what I’m using:

    HTML Code: 
    Any ideas on what i can do to amend the code?

    I understand some parts but i probably haven't mastered all of the basics (yet!)

    Thanks

  2. #2
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: Sumif only visible cells

    Would something like this help?
    Please Login or Register  to view this content.
    The 9 in Aggregate tells it to sum the list. The 5 tells it to ignore hidden rows.
    Some people volunteer in soup kitchens or hospitals. I choose to make the world better by trying to help you with Excel. We're all learning.

    <---Click * Add Reputation for all helpful comments. It's like giving a smile.
    Forum Rules: How to mark your post [Solved] and have a happier, Excel enriched life.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Sumif only visible cells

    Hi,

    Have you tried the

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    function.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: Sumif only visible cells

    I believe it is SUBTOTAL(109,Range) that ignores hidden values. That one may be helpful as well.

  5. #5
    Registered User
    Join Date
    07-27-2015
    Location
    England
    MS-Off Ver
    Office 2010
    Posts
    40

    Re: Sumif only visible cells

    Hello all

    Wow, thanks for the very quick replies.

    nigelbloomy - I don't think the Aggregate formula would work a i need to split the summed amounts out instead of summing all of it (e.g. cell A8 should show a zero value after all of the filtered rows with Apples have been summed, D8+D13=0)

    Richard Buttrey - I've not tried subtotal as i think it would just subtotal all of the visible cells in the same way as the aggregate suggestion from nigelbloomy .

    I'm not sure i even need to use a filter & might be able to find a workaround using a temporary helper column but it just seems like a much more convoluted way of doing it.

    Hopefully you might know of a more elegant approach?

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Sumif only visible cells

    @ SUMIF
    Can you attach a sample of your workbook ?
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  7. #7
    Registered User
    Join Date
    07-27-2015
    Location
    England
    MS-Off Ver
    Office 2010
    Posts
    40

    Re: Sumif only visible cells

    Hi YasserKhalil

    Sure, let me know if i you need anything else.

    Thanks
    Attached Files Attached Files

  8. #8
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Sumif only visible cells

    Quote Originally Posted by SUMIF View Post
    Hello all



    Richard Buttrey - I've not tried subtotal as i think it would just subtotal all of the visible cells in the same way as the aggregate suggestion from nigelbloomy .


    Hopefully you might know of a more elegant approach?
    Your original request was asking for the sum of all the visible cells so I'm now confused since that's precisely what the SUBTOTAL function will give you. Please explain. Preferably upload a workbook in which you have manually added the total you want so that we can understand the request in context.

  9. #9
    Registered User
    Join Date
    07-27-2015
    Location
    England
    MS-Off Ver
    Office 2010
    Posts
    40

    Re: Sumif only visible cells

    Hi Richard

    Apologies for the confusion.

    My original request was to use the SUMIF function for of all the visible cells & not just the SUM function of the visible cells. I think the SUBTOTAL function probably totals in the same was as the SUM function but if there was a SUMIF version of the SUBTOTAL function that would probably work.

    As requested i've uploaded a workbook with the cells manually added.

    Hopefully this helps clarify what i'm trying to do but let me know if not.

    Thanks
    Attached Files Attached Files

  10. #10
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Sumif only visible cells

    Hi,

    SUMIF is designed to work with ALL cells whether visible or not.

    SUBTOTAL is what you want either with the 9, or 109 parameter depending on exactly what you want. 109 excludes manually hidden rows but both will exclude values in hidden filtered rows.

  11. #11
    Valued Forum Contributor mangesh.mehendale's Avatar
    Join Date
    06-04-2015
    Location
    India
    MS-Off Ver
    2007
    Posts
    510

    Re: Sumif only visible cells

    As per my interpretation do you want following formula...

    This formula will not work in col C due to circular ref...
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Don`t care, take care...

    Regards,
    Mangesh

  12. #12
    Registered User
    Join Date
    07-27-2015
    Location
    England
    MS-Off Ver
    Office 2010
    Posts
    40

    Re: Sumif only visible cells

    Thanks Richard

    Happy to give SUBTOTAL a go but i can't imagine how it could work in a similar way to SUMIF. I need to ensure it would:

    1) only total the filtered rows &
    2) only total the rows with the same (G/L Account) value in column B.

    Perhaps i should do away with the filter & just use some sore of IF statement? The filter is used to bring up the rows with blank cells in column A that's all.

    I'm not sure of the best way to take this forward...

  13. #13
    Registered User
    Join Date
    07-27-2015
    Location
    England
    MS-Off Ver
    Office 2010
    Posts
    40

    Re: Sumif only visible cells

    Quote Originally Posted by mangesh.mehendale View Post
    As per my interpretation do you want following formula...

    This formula will not work in col C due to circular ref...
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Hi Mangesh

    Yes this is closer to what i'm looking for. I've just tested this however & unfortunately there is a problem (i don't think the SUMIF is calculating correctly).

    I've attached a workbook where I've changed the value in cell D18 from 5 to 3 (it's in yellow). Your formula is in column G & I've highlighted in red the incorrect value of zero (G18). The correct value should be -2 (cell I18).

    Thanks Mangesh
    Attached Files Attached Files

  14. #14
    Valued Forum Contributor mangesh.mehendale's Avatar
    Join Date
    06-04-2015
    Location
    India
    MS-Off Ver
    2007
    Posts
    510

    Re: Sumif only visible cells

    Ohh sorry...

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    07-27-2015
    Location
    England
    MS-Off Ver
    Office 2010
    Posts
    40

    Re: Sumif only visible cells

    Thanks for this Mangesh

    The only other problem is that the SUMIF still sums those values which are not blank.

    You can see this happening if you filter in column B for the values 222222.

    The SUMIF value is picking up the values for all 3 rows with a 222222 despite only two rows with a blank value in column A.
    Cells A13 & A16 should have a value of zero 0=2+(-2) but instead it would have 6=2+(-2)+6.


    See image (your formula is in column G:

    Query3.PNG

  16. #16
    Valued Forum Contributor mangesh.mehendale's Avatar
    Join Date
    06-04-2015
    Location
    India
    MS-Off Ver
    2007
    Posts
    510

    Re: Sumif only visible cells

    Quite hard....

  17. #17
    Registered User
    Join Date
    07-27-2015
    Location
    England
    MS-Off Ver
    Office 2010
    Posts
    40

    Re: Sumif only visible cells

    I agree

  18. #18
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Sumif only visible cells

    Can't you just use a pivot table?

  19. #19
    Registered User
    Join Date
    07-27-2015
    Location
    England
    MS-Off Ver
    Office 2010
    Posts
    40

    Re: Sumif only visible cells

    Hi Kyle123
    I think a pivot table would work but i'm not sure how to use it with VBA as i've never done it before (bad excuse i know!). It's an interesting way to do it so i might have a look for some previously written pivot table code (unless you're able help).

    I have thought of an alternative which requires the use of 4 helper columns so i may/may not go with that unless someone knows of a better way. The cells with "TRUE" in column H need to be deleted (the yellow cells show the formula for that column).

    I'll put the code in, test it & upload it on here for others.
    Query4.PNG

  20. #20
    Valued Forum Contributor mangesh.mehendale's Avatar
    Join Date
    06-04-2015
    Location
    India
    MS-Off Ver
    2007
    Posts
    510

    Re: Sumif only visible cells

    one easy way

    Sum by color... first paste following code into workbook, second filter cell and give different background color, third take a sumbycolor with formula..

    Please Login or Register  to view this content.
    Attached Files Attached Files

  21. #21
    Valued Forum Contributor mangesh.mehendale's Avatar
    Join Date
    06-04-2015
    Location
    India
    MS-Off Ver
    2007
    Posts
    510

    Re: Sumif only visible cells

    Also note that you can use above formula in your other vb code with .value = .value and then you can remove the filter and background colors..

  22. #22
    Registered User
    Join Date
    07-27-2015
    Location
    England
    MS-Off Ver
    Office 2010
    Posts
    40

    Re: Sumif only visible cells

    Thanks Mangesh, i appreciate your help with this.

  23. #23
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Sumif only visible cells

    Hi,

    Using formula :
    Formula on cell E6 (and to copy down) :
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Formula on cell C6 (and to copy down) :
    Formula: copy to clipboard
    Please Login or Register  to view this content.



    Using macro :
    Please Login or Register  to view this content.

    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. SUBTOTAL/SUMIF on autofilter visible cells only
    By crispben in forum Excel General
    Replies: 9
    Last Post: 10-23-2017, 08:39 PM
  2. When using Autofilter with SumIf, can not get it to sum only visible cells.
    By DitoPower in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-12-2013, 07:36 AM
  3. [SOLVED] Copy/Pasting Values from visible cells (using autofilter) to visible cells
    By evakotsi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-23-2012, 07:49 AM
  4. Copy Visible cells and paste values only to visible target cells
    By wotadude in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-28-2010, 04:09 AM
  5. Subtotal, Sumif Only Showing Visible
    By dprichard in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-12-2007, 08:21 AM
  6. Any way to make SUMIF only compute visible rows?
    By gtzpower in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-27-2007, 11:54 AM
  7. SumIf in Visible Cell Range
    By Terri in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-17-2005, 08:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1