+ Reply to Thread
Results 1 to 22 of 22

Sub-totaling and gross totaling

  1. #1
    Forum Contributor
    Join Date
    05-13-2019
    Location
    Halifax, Canada
    MS-Off Ver
    2016
    Posts
    176

    Sub-totaling and gross totaling

    Hi experts,

    I have a range of data that requires subtotaling and gross totaling. Trying to figure out the vba code that subtotals exactly on next row of the end of cluster and gross totals at the end.

    I have attached the document for reference.

    Thank you,
    Roshan Shakya
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    Hi !

    First just try the Excel feature SubTotal (may not need any code) …

  3. #3
    Forum Contributor
    Join Date
    05-13-2019
    Location
    Halifax, Canada
    MS-Off Ver
    2016
    Posts
    176

    Re: Sub-totaling and gross totaling

    I need that one for the automation. Sub-totaling and gross totaling are activities that I use frequently in my report. And these tasks neither come at the beginning nor at the end.

  4. #4
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Sub-totaling and gross totaling

    Quote Originally Posted by Roshan.Shakya View Post
    I need that one for the automation. Sub-totaling and gross totaling are activities that I use frequently in my report. And these tasks neither come at the beginning nor at the end.
    At least for me, not sure I understand this. Subtotal will do the work of automatting this for you and would in essence do the same thing as code. Look at the attachment. It this what you want?
    Attached Files Attached Files
    HTH
    Regards, Jeff

  5. #5
    Forum Contributor
    Join Date
    05-13-2019
    Location
    Halifax, Canada
    MS-Off Ver
    2016
    Posts
    176

    Re: Sub-totaling and gross totaling

    The result is exactly what I want.

    But considering the volume of data and the number of worksheets, subtotaling manually is time consuming. Also data range is dynamic as there are number of additions and disposal every period. So it would be great if I could write some code that will capture subtotals at different levels and at the end grand total.

  6. #6
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Sub-totaling and gross totaling

    See if you can modify the code here

    Post #14

  7. #7
    Forum Contributor
    Join Date
    05-13-2019
    Location
    Halifax, Canada
    MS-Off Ver
    2016
    Posts
    176

    Re: Sub-totaling and gross totaling

    The code you suggested is a nice piece of code but due to my ignorance I am not able to figure out how to sum/sub total exactly the same way.

    I could get the sum total exactly on the same cell by using SUMIF formula (on some other columns), condition (derived by using IF(ISNUMBER(SEARCH(""Total :"",RC[-13])),0,1)) and Loop to this condition (if 0, then).

  8. #8
    Forum Contributor
    Join Date
    05-13-2019
    Location
    Halifax, Canada
    MS-Off Ver
    2016
    Posts
    176

    Re: Sub-totaling and gross totaling

    Hi jefferrybrown,

    Can you please suggest me the code for subtotalling at different levels? I am unable to modify in the code that you have suggested as I am still a novice in coding.

    Thank you for your time.

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: Sub-totaling and gross totaling

    See if this is how you wanted.
    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    05-13-2019
    Location
    Halifax, Canada
    MS-Off Ver
    2016
    Posts
    176

    Re: Sub-totaling and gross totaling

    Thanks Jindon,

    I tested your code and it only grand totals at Row16. My requirement is to insert formula in all the highlighted cells and the rows are dynamic (changes in every reporting period). In reality, the report I have have value pasted sub-total/ grand total figure and I want to ensure that the figure as accurate. As indicated in my representative sample, which has 2 levels of totaling (VECHICLES and DOMESTIC APPLIANCES AND FURNISHINGS level and TOTAL PROPERTY LEVEL), in reality I have 4-5 sub-total levels.


    By the way, I have got this excellent piece of code from https://www.thesmallman.com/subtotal-on-the-fly, which works more or less what I require but I do not want to delete sub-totals rows that I already have. Also I am not sure if I can sum subtotals at 2nd, 3rd and 4th levels with this code.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Thank you
    Roshan Shakya
    Last edited by Roshan.Shakya; 07-20-2019 at 09:28 AM. Reason: for clarity in expression

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: Sub-totaling and gross totaling

    Sorry, but don't understand what you are trying to say.

    I just coded according to your attachment.
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    05-13-2019
    Location
    Halifax, Canada
    MS-Off Ver
    2016
    Posts
    176

    Re: Sub-totaling and gross totaling

    Why it didn't work is beyond my imagination. The code is phenomenal and I must say you are a genius. Can you please explain how it works? The code seems overwhelming to me.

    I have made slight changes in the worksheet and you can definitely help me to learn to accommodate some variations. If I could pick/set identifiers for each level, I may total the group figures for whatever levels ain't I?

    Thank you jindon for such a quick response with such an efficient code.
    Attached Files Attached Files

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: Sub-totaling and gross totaling

    Quote Originally Posted by Roshan.Shakya
    ...slight changes...
    No,,,it's a huge change.

    See if this places the formula properly.
    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    05-13-2019
    Location
    Halifax, Canada
    MS-Off Ver
    2016
    Posts
    176

    Re: Sub-totaling and gross totaling

    Thank you jindon,

    This is certainly working with very few exceptions. The exceptions are:

    1. The subtotal for 1st level and 2nd level is not captured. It captured at the base level (3rd level in my report lets say). I have designed a dummy template and consists of clusters in 3 levels. The individual clusters make the Level 2 clusters and then Level 1 clusters. So Level 1 - 1000 = Level 2 - ZAA + Level 2 - ZAB + Level 2 - ZAC + Level 2 - ZAD

    2. The code for subtotal is activated for all sheets.

    I have for my report made few changes in the code you have advised but still could not do for Level 1 and Level 2 subtotals. I have uploaded the file for your reference.
    Attached Files Attached Files
    Last edited by Roshan.Shakya; 07-20-2019 at 10:22 PM.

  15. #15
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: Sub-totaling and gross totaling

    Again?

    What is your purpose changing the data layouts all the time?

  16. #16
    Forum Contributor
    Join Date
    05-13-2019
    Location
    Halifax, Canada
    MS-Off Ver
    2016
    Posts
    176

    Re: Sub-totaling and gross totaling

    The layouts are generally dynamic since there are different but unique worksheets for a variety of circumstances. I misunderstood that it will be just a tweaking of codes for (additional blank) rows or columns and shifting of columns.

    The pattern however in both layouts is the same except there is a shifting of column E in first layout, and removal of blank rows in second layout.

    The layouts have similar patterns with extra rows after every level in the first layout (and without in the last layout). The patterns have been presented in the document enclosed.

    Thank you for your response.
    Attached Files Attached Files

  17. #17
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: Sub-totaling and gross totaling

    So what do you want to do?

    You should have uploaded a workbook with more worksheets with different data layouts.

    You are now asking almost different question.

  18. #18
    Forum Contributor
    Join Date
    05-13-2019
    Location
    Halifax, Canada
    MS-Off Ver
    2016
    Posts
    176

    Re: Sub-totaling and gross totaling

    Sorry for delayed response jindon.

    I have those 2 sheets at the moment where I perform sub-totaling. I try to fathom the code that you have suggested and noted that "x" and "r" do the sub-totaling and grand-totaling respectively. Since we have 3 layers of subtotaling can we do something like this?

    X does the first level of sub totaling (sum of all items in X)
    Y does the second level, and (sum of all Xs)
    R does the grand totaling (sum of all Ys)

    If there are more than 1 R then there will be a grand total of all Rs.

    I am sharing the screenshots for my explanation. The clue is that rows 1661 and 1662 have subtotals, which indicate first level in 1661 and second level in 1662. Similarly, rows 2377, 2378 and 2379 have subtotals that indicate first, second and third level of subtotals. So if there are consecutive sub-totals, the code should consider moving to the higher levels of sub totaling but ignoring the previous sub totals that is already used in that higher level.

    Thank you
    Roshan
    Attached Images Attached Images

  19. #19
    Forum Contributor
    Join Date
    05-13-2019
    Location
    Halifax, Canada
    MS-Off Ver
    2016
    Posts
    176

    Re: Sub-totaling and gross totaling

    Hi Jindon and respected gurus,

    Can you please help me to get this solved? The file that I have attached earlier is the exact representation of the data I am handling. I have no requirement of subtotaling in other files at the moment.

    Thank you
    Roshan Shakya

  20. #20
    Forum Contributor
    Join Date
    05-13-2019
    Location
    Halifax, Canada
    MS-Off Ver
    2016
    Posts
    176

    Re: Sub-totaling and gross totaling

    Hi respected gurus and experts,

    I am still waiting for a solution on this? Shall I close this thread?

    Thank you
    Roshan Shakya

  21. #21
    Forum Contributor
    Join Date
    05-13-2019
    Location
    Halifax, Canada
    MS-Off Ver
    2016
    Posts
    176

    Re: Sub-totaling and gross totaling

    Respected experts, gurus and MVPs,

    I have come up with simple subtotal solution on varying levels of totals but for this matter, I have renamed the Total to Total: (in 2nd Level) and Grand Total: (in 3rd Level). I am attaching the solution herewith with the code below.

    Please Login or Register  to view this content.
    In my report, my problem is I cannot rename Total in 2nd level and 3rd level to Total: and Grand Total: respectively. Can I tweak something in the code so that I do not have to work manually on source data? The original data has all value pasted figures. I would want to close this post and would request for the solution.

    Thank you
    Roshan Shakya
    Attached Files Attached Files

  22. #22
    Forum Contributor
    Join Date
    05-13-2019
    Location
    Halifax, Canada
    MS-Off Ver
    2016
    Posts
    176

    Re: Sub-totaling and gross totaling

    Thank you all gurus and experts for your contribution and sharing your valuable knowledge. I am closing this thread as solved.

    Roshan Shakya

+ 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] Totaling columns
    By tapsmiled in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-27-2014, 06:47 PM
  2. Replies: 5
    Last Post: 08-21-2013, 12:55 PM
  3. Auto Totaling
    By rhyan66 in forum Excel General
    Replies: 7
    Last Post: 06-08-2009, 06:47 PM
  4. Totaling a Sum for every 7 days
    By seanrigby in forum Excel General
    Replies: 5
    Last Post: 06-28-2006, 01:20 PM
  5. IF= Cells not totaling
    By Bradley in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-20-2006, 06:45 PM
  6. Sub-Totaling
    By tamxwell in forum Excel General
    Replies: 2
    Last Post: 11-10-2005, 10:45 AM
  7. Sub-Totaling
    By tamxwell in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-09-2005, 09:35 PM

Tags for this Thread

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