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 8612787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:42:49+00:00 2026-06-12T04:42:49+00:00

I’m fairly new to VBA, however I have a programming background. I’m writing VBA

  • 0

I’m fairly new to VBA, however I have a programming background. I’m writing VBA to open two excel workbooks, copy the pivot tables and paste special the values into a staging workbook. From there, I need to compare the pivot data and output the differences. However, I’m not sure where to go from there.

Sample Data

Pivot 1

Sum of Fruits          YearMon
Category       Group   201205 201206 201207 201208 201209 ... 201401
Apples         Green                    1.3    2.1    3.0 ...
               Red                      1.0    1.5    2.0 ...
Apples Total                            ..     ..     ..  ...
Berries        Straw        1      1    1.1    2.0    2.1 ...
               Black        1      1    1.0    0.9    0.9 ...
Berroes Total                           ..     ..     ..  ...

Pivot 2

Sum of Fruits          YearMon
Category       Group   201206 201207 201208 201209 201210 ... 201402
Apples         Green                    1.5    2.3    3.2 ...
               Red                      0.8    1.3    1.9 ...
               Yellow              1    0.9    0.9      1 ...
Apples Total                            ..     ..     ..  ...
Berries        Straw        1      1    1.3    1.8    2.1 ...
               Black        1      1    0.9    0.8    0.8 ...
Berroes Total                           ..     ..     ..  ...

Desired Result (Pivot 2 – Pivot 1)

Sum of Fruits          YearMon
Category       Group   201205 201206 201207 201208 201209 201210 ... 201402
Apples         Green                          -0.6   -0.7        ...
               Red                            -0.7   -0.7        ... 
Apples Total                            ..     ..     ..         ...
Berries        Straw               0   -0.1   -0.7   -0.3        ...
               Black               0      0      0   -0.1        ...
Berries Total                           ..     ..     ..         ...

My first impulse is to put YearMon and Group into arrays based on each Category, then looping through them to remove attributes which don’t exist in both pivots (ie. yellow apples don’t exist in Pivot 1, and there is no data for 201402). I would then loop through each group and do the calculation. This sounds too messy.

I’m currently thinking to create a range for YearMon and Group, then looping through the range, vertically and horizontally, for each Category to compare the values. I’m not sure how to exactly find where each Category stops, or whether I could perhaps use VLOOKUP? Or is there some simpler way to compare two pivots?

Update 1

The majority of the comments recommend that I try to use the source data behind the pivot to accomplish this task. I’m able to get the data and following the scheme above, which looks like:

Data 1

Category Group YearMon Value
Apples   Green 201207  1.3
Apples   Green 201208  2.1
Apples   Green 201209  3.0
Apples   Red   201207  1.0
Apples   Red   201208  1.5
Apples   Red   201209  2.0
Berries  Straw 201205  1.0
Berries  Straw 201206  1.0
Berries  Straw 201207  1.1
Berries  Straw 201208  2.0
Berries  Straw 201209  2.1
Berries  Black 201205  1.0
Berries  Black 201206  1.0
Berries  Black 201207  1.0
Berries  Black 201208  0.9
Berries  Black 201209  0.9

Data 2

Category Group YearMon Value
Apples   Green  201208  1.5
Apples   Green  201209  2.3
Apples   Green  201210  3.2
Apples   Red    201208  0.8
Apples   Red    201209  1.3
Apples   Red    201210  1.9
Apples   Yellow 201207  1.0
Apples   Yellow 201208  0.9
Apples   Yellow 201209  0.9
Apples   Yellow 201210  1.0
Berries  Straw  201206  1.0
Berries  Straw  201207  1.0
Berries  Straw  201208  1.3
Berries  Straw  201209  1.8
Berries  Straw  201210  2.1
Berries  Black  201206  1.0
Berries  Black  201207  1.0
Berries  Black  201208  0.9
Berries  Black  201209  0.8
Berries  Black  201210  0.8

After attempting SUMIFS as suggested below, it appears that I would need to specify each criteria (Category, Group, YearMon) for each data set to do the comparison. Perhaps there is some other functionality that would work?

Update 2

Another suggestion was to combine the data sets to calculate the difference from in a pivot. After combining these two data sets, I can’t seem to figure out a way to do the difference calculation without including another column that identifies each data set (1 or 2). From there I’m able to do the comparison. Am I doing something incorrectly?

Update 3

Following an answer below, I’ve simply negated the values of the second data set to get the difference.

  • 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-06-12T04:42:51+00:00Added an answer on June 12, 2026 at 4:42 am

    To demonstrate what I was suggesting. Take your Data 1, multiply all amounts by -1, and add Data 2 to it, gives you:

    Combined Data

    Doing a pivot table based on that combined data gives you:

    New Pivot Table

    The pivot table SUM does the difference for you, for whatever row/column combinations you want. The trick is the multiplying one Data set by -1

    Trick: Type -1 in a new cell, Ctrl-C on that cell, then select all the values in Data 1 group, then do Paste Special and select ‘Multiply’

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.