+ Reply to Thread
Results 1 to 18 of 18

Array Subtotal Macro

  1. #1
    Registered User
    Join Date
    09-07-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2007
    Posts
    8

    Array Subtotal Macro

    Hi Everyone,

    I have this code that searches for the blank cells that I have created and subtotals the values above.
    This is perfect & exactly what I need, EXCEPT, I need it to do this for not just column F but F:V & can't seem to get this worked out to do so. I learned programming in pascal & java back in high school (6+ years) so I have a little background but VBA is an entirely different beast and I can't quite get anything to work.

    Is there a way to make this so the subtotal can be arrayed during the procedure or after it's executed?

    Any help is much appreciated.



    [code]
    Dim StartRow As Integer
    Dim EndRow As Integer

    StartRow = 11
    EndRow = Range("F5550").End(xlUp).Offset(1, 0).Row
    For i = StartRow To EndRow
    If Cells(i, "F") = "" And i > StartRow Then
    Cells(i, "F").Formula = "=SUM(F" & StartRow & ":F" & i - 1 & ")"
    StartRow = i + 1
    End If
    Next
    [code/]

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Array Subtotal Macro

    You can loop through columns also. Like maybe:
    Please Login or Register  to view this content.
    Untested.
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Registered User
    Join Date
    09-07-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Array Subtotal Macro

    Hi XeRo,

    Thanks for the response.

    I tested it and its throwing back a false value in the column F blanks and nothing in F:V.

  4. #4
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Array Subtotal Macro

    Hmm, so the point of the code is to loop through all cells in F:V and if the cell is blank, total all cells up to last empty (subtotaled) cell?

  5. #5
    Registered User
    Join Date
    09-07-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Array Subtotal Macro

    Correct.
    Would the rest of the code prior to this bit be helpful?

  6. #6
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Array Subtotal Macro

    Lets take a look, just to make sure there aren't any conflicts.

  7. #7
    Registered User
    Join Date
    09-07-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Array Subtotal Macro

    Please Login or Register  to view this content.

  8. #8
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Array Subtotal Macro

    Okay, it looks like you're inserting the rows for the subtotals. I will assume that there won't be two blank cells in a row. Try:
    Please Login or Register  to view this content.
    e/ I just realized this errors at the bottom of the columns. Let me rework.
    Last edited by Solus Rankin; 08-27-2013 at 11:19 AM.

  9. #9
    Valued Forum Contributor
    Join Date
    07-17-2005
    Location
    Abergavenny, Wales, UK
    MS-Off Ver
    XL2003, XL2007, XL2010, XL2013, XL2016
    Posts
    608

    Re: Array Subtotal Macro

    Hi

    You could replace all of that with this

    Please Login or Register  to view this content.
    --
    Regards
    Roger Govier
    Microsoft Excel MVP

  10. #10
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Array Subtotal Macro

    or
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    09-07-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Array Subtotal Macro

    Roger, yours errors out somewhere.

    Xero - it subtotals the first space but then every thing after it subtotals anything and everything that is above.

    I've moved the first bit of this macro to the one before this.

    Just background on this - our estimating server crashed (no loss, it was old and clunky and written in Apache Tomcat) but there was no warning so I threw something together so I could finish my bid. This has been significantly improved, but there is still the missing link between a bid and it being a project.
    This is for our project managers - once we are awarded, this sheet is intended to pull all the data from the estimate tab, let them assign job codes, and subtotal it (which is data our ERP system requires).
    So
    Macro 1 pretties up the data from the estimate into a manageable form for them to assign job numbers.
    Macro 2 sorts and filters the job numbers once they are assigned (and now inserts lines so there is a place for the subtotal to go(this is what moved).
    Macro 3 is what we are trying here, and its to insert subtotals from column f to column v only subtotalling to the previous blank - which is what I had for column f and was wondering if I could array. Or is there even a possibility that the original macro I posted here can be arrayed or copy/pasted after the initial column (f) runs through. It would be the same formula (=sum) across the board.

  12. #12
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Array Subtotal Macro

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    09-07-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Array Subtotal Macro

    Perfect!

    Out of curiosity though, is there a way so it shows the formula instead of just printing what the subtotal is?

  14. #14
    Valued Forum Contributor
    Join Date
    07-17-2005
    Location
    Abergavenny, Wales, UK
    MS-Off Ver
    XL2003, XL2007, XL2010, XL2013, XL2016
    Posts
    608

    Re: Array Subtotal Macro

    Hi

    It worked fine on some test data I created.
    It would be helpful if you uploaded a copy of your data with details of what you want before and after.

  15. #15
    Registered User
    Join Date
    09-07-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Array Subtotal Macro

    Roger, I can't upload the file due to the nature of what the file contains.

  16. #16
    Valued Forum Contributor
    Join Date
    07-17-2005
    Location
    Abergavenny, Wales, UK
    MS-Off Ver
    XL2003, XL2007, XL2010, XL2013, XL2016
    Posts
    608

    Re: Array Subtotal Macro

    Well, can you just create a small sample file with some dummy data.
    I would be interested to see where my code failed.

  17. #17
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Array Subtotal Macro

    Yeah I'm sure there is, but I was struggling with converting column numbers into column letters (it can be done with an added Function) that the formula would understand. Therefore, I used application.worksheet function so that I could use the cells property and refer to them with column numbers.

  18. #18
    Registered User
    Join Date
    09-07-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Array Subtotal Macro

    XeRo, no worries, it is much appreciated. The PMs will likely complain, but hey, this gets them a heck of a lot farther & faster than they would otherwise

    Roger -
    it errored out here:
    Please Login or Register  to view this content.
    I can get some dummy info together, lunch first though !

+ 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 Array
    By GreenTee in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-12-2013, 05:07 PM
  2. Subtotal and array formula
    By Zinadra in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-17-2013, 02:14 PM
  3. Subtotal - Delete zero Subtotal and prior rows that calculate to that zero Subtotal
    By Whatsherface in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-14-2012, 08:37 PM
  4. [SOLVED] =Subtotal(countif,Range); Subtotal and countif in 1 formula [SOLVED]
    By thomas.mapua in forum Excel General
    Replies: 5
    Last Post: 01-06-2012, 11:33 AM
  5. Excel 2007 : Sum if array formula into Subtotal
    By mhDallas in forum Excel General
    Replies: 1
    Last Post: 05-06-2010, 02:52 AM

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