Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 417691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:36:18+00:00 2026-05-12T18:36:18+00:00

I have data of this form: Category Source Amount Dues FTW $100 Donations ODP

  • 0

I have data of this form:

Category      Source      Amount
Dues          FTW         $100
Donations     ODP         $20
Donations     IOI         $33
Dues          MMK         $124

There is no sort order. The categories are unknown at compile time. I want a VBA macro to cycle through the range, output a list of distinct values, with the subtotals for each. For the above data, it would look like this:

Category      Total Amount
Dues          $224
Donations     $55

How can I do this? Also, is there a way to make the macro run every time the table above is updated, or is it necessary for the user to click a button?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T18:36:19+00:00Added an answer on May 12, 2026 at 6:36 pm

    You may want to use a built in Excel feature to do this. Looping can take a long time and be problematic if you have a lot of values to loop through.

    Something like the following might get you started on creating a pivot table (from http://www.ozgrid.com/News/pivot-tables.htm)

    Sub MakeTable()
    Dim Pt As PivotTable
    Dim strField As String
    
        'Pass heading to a String variable
        strField = Selection.Cells(1, 1).Text
    
        'Name the list range
        Range(Selection, Selection.End(xlDown)).Name = "Items"
    
        'Create the Pivot Table based off our named list range.
        'TableDestination:="" will force it onto a new sheet
        ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, _
            SourceData:="=Items").CreatePivotTable TableDestination:="", _
                TableName:="ItemList"
    
        'Set a Pivot Table variable to our new Pivot Table
        Set Pt = ActiveSheet.PivotTables("ItemList")
    
        'Place the Pivot Table to Start from A3 on the new sheet
        ActiveSheet.PivotTableWizard TableDestination:=Cells(3, 1)
    
        'Move the list heading to the Row Field
        Pt.AddFields RowFields:=strField
        'Move the list heading to the Data Field
        Pt.PivotFields(strField).Orientation = xlDataField
    End Sub
    

    This is for subtotals (though I much prefer pivot tables)
    http://msdn.microsoft.com/en-us/library/aa213577(office.11).aspx


    EDIT:
    I reread and have the following thoughts. Set up the pivot table on a separate sheet (without using any code) then put the following code on the sheet that has the pivot table so that the table will update everytime the sheet is selected.

        Private Sub Worksheet_Activate()
    
        Dim pt As PivotTable
    
            'change "MiPivot" to the name of your pivot table
            Set pt = ActiveSheet.PivotTables("MyPivot")
    
            pt.RefreshTable
    
        End Sub
    

    Edit #2
    Refresh all pivot tables on sheet
    http://www.ozgrid.com/VBA/pivot-table-refresh.htm

    Private Sub Worksheet_Activate()    
        Dim pt As PivotTable
    
        For Each pt In ActiveSheet.PivotTables
            pt.RefreshTable
        Next pt
    End Sub
    

    The link has multiple options on how to refresh pivot tables in the sheet/workbook.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data in this form (dictionary): Value0 Text1 Value1 Text2 Value2 Text3
I have a html form with the data by this post method 'form id='form1'
I send data in this way: <form method=post enctype=text/plain action=Func> And I have a
I have this HTML: <form action='uploadhandle.php' method='POST' enctype=multipart/form-data> <input type='file' class='fileinput' id='photo1' name='photo1'> <input
I have the following form <form name=myForm id=myForm method=post enctype=multipart/form-data action=script.php> and this jQuery
I have this form <form action= method=post enctype=multipart/form-data name=form1 id=form1> <tr> <td width=32% valign=top>&nbsp;&nbsp;&nbsp;<strong
I have a multi-step order form built in this manner: Step 1: Choose category
I have data in this format coming from a database... BUS 101S Business and
I have data like this: Team | goal a | 5 b | 8
Say I have data like this: <option value=abc >Test - 123</option> <option value=def >Test

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.