+ Reply to Thread
Results 1 to 13 of 13

Creating VBA Macro For Grouping and Summation by Account Code

  1. #1
    Registered User
    Join Date
    01-27-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    4

    Creating VBA Macro For Grouping and Summation by Account Code

    I run monthly phone usage reports for my work, and I'm having trouble creating a macro that can autosum the duration of the call in column B in a 00:00:00 format by the account number listed in column J.

    I've attached an example:

    I appreciate any thoughts!
    Attached Files Attached Files
    Last edited by kmstyf; 01-27-2012 at 02:20 PM. Reason: By moderator request.

  2. #2
    Registered User
    Join Date
    01-27-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Need Help Creating Macro

    Thanks for the pointer. I've changed the title to be more specific. I appreciate your response.

  3. #3
    Registered User
    Join Date
    01-27-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Need Assistance with Creating VBA Macro For Grouping and Summation by Account Cod

    Any ideas?

  4. #4
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Need Assistance with Creating VBA Macro For Grouping and Summation by Account Cod

    So if the account is 104 then you would want the sum of just those values in B?
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  5. #5
    Registered User
    Join Date
    01-27-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Need Assistance with Creating VBA Macro For Grouping and Summation by Account Cod

    Exactly, I just need to be able to separate the 00:00:00 values by account code, and then autosum all the values in that column. Should be pretty simple, but I'm not very good with excel. Getting better, just not quite there yet.
    Last edited by kmstyf; 01-27-2012 at 05:45 PM.

  6. #6
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Need Assistance with Creating VBA Macro For Grouping and Summation by Account Cod

    I'm working on it but for some reason the sum is always 00:00:00 and I can't figure out why. I have asked the real gurus on this site to lend a hand so be patient and I'm sure you'll get an answer soon.

  7. #7
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Need Assistance with Creating VBA Macro For Grouping and Summation by Account Cod

    kmstyf,

    Could give this code a try:
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  8. #8
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Need Assistance with Creating VBA Macro For Grouping and Summation by Account Cod

    kmstyf,

    If you're interested in a non-vba solution, a pivot table can provide the same results. Unfortunately I can't seem to upload a file at the moment to show you what it looks like, though

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Need Assistance with Creating VBA Macro For Grouping and Summation by Account Cod

    The problem is the values in column B "look" like time values but are in fact, text strings.

    1) Copy the cell C3 which has a value of 0 in it, handy
    2) Highlight the values in column B
    3) Select Edit > Paste Special > Add > OK

    Now all the values are turned into time values...look like decimals right now.

    4) Format those cells again as [h]:mm:ss and you'll get your original look back


    Now you can SUM those values. Or you can use a SUMIF() to sum the values based on the codes in column J.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Need Assistance with Creating VBA Macro For Grouping and Summation by Account Cod

    Hi JB
    I looked at the OP's file for about an hour today trying to reformat those cells (Column B) and couldn't make it happen. Can you share with me what this does
    3) Select Edit > Paste Special > Add > OK
    I SEE what it does but what's it doing under the covers? Add???...don't know what it's doing.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Creating VBA Macro For Grouping and Summation by Account Code

    If you add 0 to any number it leaves the number the same.

    The Paste Special > ADD will attempt to add the number currently in memory to every selected cell, a very "special" paste, indeed!

    Interestingly, if you have a "text" string that looks like a number, adding 0 to in this manner will actually convert it to a real Excel number. Then you can change the formatting since it is now a number, back to the TIME display of your choosing.


    It is well worth your time to go through all the PASTE SPECIAL options and wrap your head around what they can do. In combination with the F5 > Special (select) those two tools can be very powerful and quick to use for transforming large amounts of data.

  12. #12
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Creating VBA Macro For Grouping and Summation by Account Code

    Hi kmstyf

    Using JB's excellent tip, try this code
    Please Login or Register  to view this content.

  13. #13
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Creating VBA Macro For Grouping and Summation by Account Code

    kmstyf,

    I'm finally able to upload the example file showing the pivot table
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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