+ Reply to Thread
Results 1 to 4 of 4

Sum across columns based on column headers or count of columns

  1. #1
    Registered User
    Join Date
    05-17-2010
    Location
    Tennessee
    MS-Off Ver
    Office365
    Posts
    24

    Sum across columns based on column headers or count of columns

    I'm writing a macro using Office 365. I'm a beginning/intermediate vba coder. I only get the opportunity every now and then so I feel my way through.

    A piece of the macro needs to be as follows:

    Workbook Setup:
    I have two sheets in a workbook.
    One has a pivot table summing the revenue of customers by month date for 1 year. Columns = months, Rows = Customers
    The second sheet is a pivot table in the same format, for different. On the second sheet however, there is only a partial years data. So on the first sheet there is Jan-Dec and on the second, only Jan-Mar. The amount number of months on the second sheet changes so it needs to be versatile depending on when the report is run.

    What I need them to do:
    I need to create a column on the second sheet, at the end of the pivot table, that sums the same months from the first sheet on each row. So, if the second pivot table has months Jan-Apr, I need to the macro to sum across the totals for only Jan-Apr from the first pivot table.

    I have attached a workbook that hopefully will make this a little clearer. Any suggestions or code on how to approach this would be very helpful.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    05-08-2015
    Location
    Uvalde, TX
    MS-Off Ver
    2010
    Posts
    720

    Re: Sum across columns based on column headers or count of columns

    Hi,

    While I am sure there is a VBA Guru out there that can figure this out, I think you would be better served with an INDEX MATCH formula.

    See that attached modification of your example.

    It uses INDEX MATCH MATCH formula's that reference Dynamic Named Arrays to return the requested info.
    The benefit of Dynamic Named Arrays is that they will automatically include any new information contained in your reference data. In this case the "Last Year" data.

    Let me know if you have any questions.

    Hope this is helpful.

    Cheers
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    05-02-2015
    Location
    calgary alberta
    MS-Off Ver
    2012
    Posts
    205

    Re: Sum across columns based on column headers or count of columns

    the index match seems to work, im intrested to see if someone shows a VBA code to see how it works within the pivot tables

  4. #4
    Registered User
    Join Date
    05-17-2010
    Location
    Tennessee
    MS-Off Ver
    Office365
    Posts
    24

    Re: Sum across columns based on column headers or count of columns

    Hi southward. Thanks for the reply. I love an index match formula. Unfortunately, this doesn't quite get me where I need to be. I could use the index match match if I were trying to manually return multiple results in multiply columns as you showed.

    However, this is going to be a regularly run macro and it needs recognize that the months showing are Jan thru Apr, then give me a sum of those months from the first sheet. In other words, I'm trying to compare combined total for a customer from the second sheet the combined totals of those same months from the first. If Customer 1 is showing a total of 11,441 for Jan through Apr of 2017, I need (in one column) to see the total of Jan through Apr of the previous year, which in this case would be 10,511. And it's only a piece of a larger macro being run. I'm happy to use a formula within the macro to get me there but I'm not sure of one or even a combination that accomplishes this.

    I do thank you for you thoughts and welcome any other suggestions. I'm quite stumped on this one.
    Last edited by RandiLee; 12-08-2016 at 10:13 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. copy and paste columns based on column headers
    By patwary786 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-24-2015, 11:43 PM
  2. Replies: 1
    Last Post: 06-19-2014, 06:35 PM
  3. Get value based on columns and row headers
    By KJL in forum Excel General
    Replies: 2
    Last Post: 05-06-2014, 01:36 PM
  4. Count Number of occurences Across Columns based on Similar Column Headers
    By vidyuthrajesh in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 06-27-2013, 06:42 PM
  5. Summary - Copy the columns based on column headers
    By rafiomeon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-01-2012, 10:32 AM
  6. Create a new column based on count of two other columns
    By ftcnt in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-22-2012, 09:10 AM
  7. Macro to Sum Columns based on Headers
    By Jluc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-24-2011, 02:36 PM

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