+ Reply to Thread
Results 1 to 3 of 3

Trying to build loop with conditional sums

  1. #1
    Registered User
    Join Date
    10-30-2014
    Location
    San Francisco, CA USA
    MS-Off Ver
    2007 and 2010
    Posts
    2

    Trying to build loop with conditional sums

    Hello All,

    I've been spending several hours to no avail in attempt to write a script to do some conditional sums and deletion of rows and was hoping to find some ideas on here.

    Problem: I am trying to sum the numbers in column's A, B and C that relate to the same item number but only at locations D1 or any location beginning with an S per the table below. In this example, the numbers in the rows with D2 or D3 can be ignored. After the number's are summed, I would like to paste them all in one row and delete any extraneous rows.

    Sample Table before modification:

    Item Location A B C D E F
    12345 D1 2 4 45 # # #
    12345 D2 4 5 6 # # #
    12345 D3 6 2 4 # # #
    12345 S1 8 2 3 # # #
    12345 S2 2 7 3 # # #
    111111 D1 4 8 5 # # #
    111111 D2 2 43 8 # # #
    111111 S3 1 3 9 # # #


    Desired Output:

    Item Location A B C D E F
    12345 D1 12 13 51 # # #
    111111 D1 5 11 14 # # #


    Anyone have any thoughts on how to best approach this?

    I have been able to write some VBA to delete any extraneous rows that don't need to be summed (Per example, locations D2 and D3) but I can still not figure out how to sum the remaining numbers to make the output look like the desired output above. I'm presuming I need to make some sort of temporary table or loop to do the math in?

    Any thoughts or direction would be appreciated!

    Mike

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Trying to build loop with conditional sums

    A simple pivot table with a helper column in the source will do that

    Please confirm whether Pivot Solution is acceptable.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    10-30-2014
    Location
    San Francisco, CA USA
    MS-Off Ver
    2007 and 2010
    Posts
    2

    Re: Trying to build loop with conditional sums

    I've definitely tried that! The problem I've run in to there would be where I have put the general # signs above, there are other values I do not want to be summed, I would like those values to remain the same as they are in the rows with the location D1. (I should have mentioned that before).

    I tried to attach an example spreadsheet but my connection is timing out this morning..

    Or is there a way in a pivot table to subtotal certain columns and keep others as the value of a specific cell/row that you may know of?

    Thanks!

+ 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. VBA Code that Sums on a Loop Based on Criteria and Linked to Calender
    By mkeys4 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-24-2013, 09:15 AM
  2. [SOLVED] Conditional Sums
    By GarrySmo in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-26-2012, 08:29 AM
  3. Can I build variable names in a VBA loop?
    By barryleajo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-20-2010, 12:31 PM
  4. Replies: 0
    Last Post: 05-27-2010, 02:04 PM
  5. Macro - Series of formulas in a loop to build tables
    By kostas in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-09-2008, 05:38 AM

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