Consulting

Results 1 to 2 of 2

Thread: Subtotal calculation using Macro

  1. #1
    VBAX Newbie
    Joined
    Aug 2007
    Posts
    4
    Location

    Question 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 (abcd, mnop, wxyz). 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.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,455
    Location
    [vba]

    Columns("A").Subtotal GroupBy:=1, _
    Function:=xlSum, _
    TotalList:=Array(3, 4), _
    Replace:=True, _
    PageBreaks:=False, _
    SummaryBelowData:=True
    ActiveSheet.Outline.ShowLevels RowLevels:=2
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •