Consulting

Results 1 to 5 of 5

Thread: Macros to add rows and subtotals

  1. #1

    Macros to add rows and subtotals

    Here is the sample of my excel data:
    BETTY 20 HEW A 22
    BETTY 20 HEW B 0
    BETTY 20 HEW C 1
    BETTY 20 HEW D 7
    BETTY 20 HEW E 10
    BETTY 20 HEW F 64
    BETTY 20 HEW G 4
    BETTY 23 THOMAS A 0
    BETTY 23 THOMAS B 0
    BETTY 23 THOMAS C 0
    BETTY 23 THOMAS D 0
    BETTY 23 THOMAS E 0
    BETTY 23 THOMAS F 0
    BETTY 23 THOMAS G 0

    I would like to have a macro that automatically add rows for every data change in column 3 and add subtotals for column 5. Final data will look like this:
    BETTY 20 HEW A 22
    BETTY 20 HEW B 0
    BETTY 20 HEW C 1
    BETTY 20 HEW D 7
    BETTY 20 HEW E 10
    BETTY 20 HEW F 64
    BETTY 20 HEW G 4
    Subtotal 108

    BETTY 23 THOMAS A 0
    BETTY 23 THOMAS B 0
    BETTY 23 THOMAS C 0
    BETTY 23 THOMAS D 0
    BETTY 23 THOMAS E 0
    BETTY 23 THOMAS F 0
    BETTY 23 THOMAS G 0
    Subtotal 0

    Thank you!

    Alvin

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You can use Excel's Subtotal feature to do this for you.


    • Make sure the data has a header row

    • Select the data

    • From the Worksheet Menu Bar select Data

    • Select Subtotals...

    • At each change in: {Column C Header}

    • Use function: {Sum}

    • Add subtotal to: {Column E Header}

    • Ok

  3. #3
    It works! Thanks!

  4. #4
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi asugianto, and welcome to VBAX!Did you know that you can mark your own threads solved here? Just see the note in my signature.

    I'll get this one for you!
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  5. #5
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You're Welcome

    Take Care

Posting Permissions

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