+ Reply to Thread
Results 1 to 6 of 6

Macro help: Sum only visible, non-sequential cells across columns

  1. #1
    Registered User
    Join Date
    02-17-2016
    Location
    Michigan, US
    MS-Off Ver
    MS Office 2013
    Posts
    3

    Macro help: Sum only visible, non-sequential cells across columns

    Hi,

    I maintain a budget document and one sheet in the workbook displays Budget, Actual, and Difference values for each month. The last three columns show YTD sums for Budget, Actual, and Difference. (See the image for help visualizing.)
    My predecessor apparently would essentially start from scratch for each month's totals, using simple SUM formulas in the YTD that she updated at the end of each month. I stubbornly (perhaps too much) believe that there is a better way to do this, in which I can build formulas for every column in every month that reference Budget and Actual sheets, so the numbers feed in automatically (which I have done already); then, for the YTD section, I insert a formula that adds up only the visible cells (as you can see, I have each month grouped so I can hide the future months). The end result would be a dream world in which I plug numbers into the Actual column, hide the months I don't want to total, and the YTD section reflects the correct totals.

    I've searched around for SumVisible VBA macros, which do half of the job for me. The problem is that I'm trying to sum non-sequential cells (Budget+Budget, Actual+Actual, etc), so the usual SumVisible(range) setup doesn't work. I've tested it by CTRL-clicking only the cells I want to sum, for example SumVisible(A1,C1,E1), and that returns a VALUE error. I have no prior experience with excel macros, but I do know a little about programming logic so I tried to tinker with the macro to make it do what I want. With the following setup, it no longer returns an error...rather, it only returns a value of 0. Any help on making this work would be appreciated.

    HTML Code: 
    sheet image.png
    Last edited by EricJames; 02-17-2016 at 04:46 PM.

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Macro help: Sum only visible, non-sequential cells across columns

    So the way your code is structured, x is determined by the value of the LAST cell in Reference. If it's 1, x will be 1. If it's not 1, x will be zero.

    So SumSpecial is returning zero because the last cell in your reference range doesn't have a 1 in it, thus every cell value is being multiplied by zero in your ToSum loop.

    What would help is if you posted a workbook with data populated in it, and then with notes in cells that said like "if I typed =SpecialSum("A1:A2", "B1:B10") in this cell I would expect it to equal 6 for reasons x, y, and z". A couple three examples like that would be nice.
    I'm interested in starting a career working with VBA, if anyone knows of any opportunities!

  3. #3
    Registered User
    Join Date
    02-17-2016
    Location
    Michigan, US
    MS-Off Ver
    MS Office 2013
    Posts
    3

    Re: Macro help: Sum only visible, non-sequential cells across columns

    I see, that makes sense. Testing it out with the attached workbook proved that point. A quick test of hiding columns showed that the "sum visible only" portion of the code is working just fine. How do I re-work the "non-sequential" portion so that it checks each cell in ToSum sequentially with its coordinating Reference cell?
    I hope I've managed to convey the logic behind my thinking well enough, between my original post and my notes in the workbook.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Macro help: Sum only visible, non-sequential cells across columns

    For your Reference Range, you can just select/type in one cell in the correct row if you want, or the whole range; it wouldn't matter.

    Please Login or Register  to view this content.
    Also, awesome example spreadsheet. If everyone provided examples like this, I would be so happy.

  5. #5
    Registered User
    Join Date
    02-17-2016
    Location
    Michigan, US
    MS-Off Ver
    MS Office 2013
    Posts
    3

    Re: Macro help: Sum only visible, non-sequential cells across columns

    That seems to have done the trick - thanks so much!

  6. #6
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Macro help: Sum only visible, non-sequential cells across columns

    Great, please mark this thread SOLVED, and any reputation (the star in the lower left of the posts) is appreciated.

    To mark solved, select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ 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. [SOLVED] copy sequential columns / paste to non-sequential columns
    By macrorookie in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-09-2014, 04:59 PM
  2. autofill multiple columns and visible cells only
    By njan1982 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-27-2013, 11:28 PM
  3. Paste into visible columns/cells only
    By VJayakumar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-16-2013, 05:21 PM
  4. Select Visible Cells in Specific Columns
    By RyanPJK in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-14-2013, 12:10 PM
  5. [SOLVED] Create sequential letters (A, B, C) in sequential cells
    By Theale in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 08-29-2012, 02:47 PM
  6. Resize Visible Rows based only on Visible Columns text
    By Zimbo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-22-2009, 10:55 AM
  7. Sequential numbering for visible cells
    By skaura in forum Excel General
    Replies: 1
    Last Post: 07-21-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