+ Reply to Thread
Results 1 to 5 of 5

Subtotal calculation using Macro

  1. #1
    Registered User
    Join Date
    05-20-2008
    Posts
    3

    Subtotal calculation using Macro

    Hello,

    I have been trying to create an excel macro that should do a subtotal of some selected fields in my worksheet. The worksheet table looks something like:

    CLIENT ORDER NO SALES H1 SALES H2
    abcd 1234 100 300
    abcd 1235 200 400
    abcd 1240 500 100
    mnop 1212 600 700
    wxyz 1300 100 200
    wxyz 1315 300 400
    wxyz 1325 500 600
    wxyz 1335 700 800

    What the macro should do is to do a subtotal of the sales in H1 and H2 against each of these clients. That is, the output of the macro should be like:

    CLIENT SALES H1 SALES H2
    abcd 800 800
    mnop 600 700
    wxyz 1600 2000

    I know how to do it manually using the SUBTOTAL function, but I need to implement this feature in a macro, which I am not able to do. Could anyone kindly provide me with some assistance please.

    Cheers.
    Last edited by VBA Noob; 05-26-2008 at 04:11 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Use a PivotTable, you don't need a macro.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    05-20-2008
    Posts
    3

    Subtotal calculation using Macro

    Quote Originally Posted by royUK
    Use a PivotTable, you don't need a macro.
    Hello royUK

    I tried to get this done using pivot tables, but somehow I am not able to. The main problem I am having is to arrange Sales H1 and Sales H2 side-by-side. If I add Sales H1, I am not able to add Sales H2 next to it.

    I must admit that I have not used pivot tables that way, so this apparently simple task looks like a show-stopper for me. Could you kindly give me some suggestion please.

    Oh... by the way, I am using Excel 2003.

    Thank you for your help.

    Cheers.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Can you attach an example workbook?

  5. #5
    Registered User
    Join Date
    05-20-2008
    Posts
    3

    Subtotal calculation using Pivot Tables

    Quote Originally Posted by royUK
    Can you attach an example workbook?
    Hello royUK,

    Sorry for this delayed response. I have attached a sample file for your kind reference.

    My exact problem is a bit strange and seems to have something to do with the changed behaviour of pivot tables in excel 2007 as compared to Excel 2003. The attached workbook is created in Excel 2007 and contains the base table on top and below it the designed pivot table.

    This table does actually work if you have Excel 2007 - no issues at all. But if I share it with someone having Excel 2003, the table doesn't work (I mean it doesn't refresh). I was not sure in which forum should I had to raise this issue, so I did it here. Could you kindly suggest how to resolve this or let me know where could I raise this please.

    Thank you for your help.

    Cheers.
    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