+ Reply to Thread
Results 1 to 12 of 12

How to use VBA LOOP to sum categories into a Cell

  1. #1
    Registered User
    Join Date
    09-06-2017
    Location
    portland, oregon
    MS-Off Ver
    2016
    Posts
    33

    How to use VBA LOOP to sum categories into a Cell

    Hi everyone. I am trying to create a loop to SUM values in a given range if they meet a certain criteria. Essentially the loop should be looking for 2 values, "Office Name" and "Product Category". The sum for each category will be placed into a cell value. I have attached a WB outlining what I am trying to achieve. Thank you everyone for your time!
    Attached Files Attached Files
    Last edited by jdcortez; 02-19-2019 at 09:48 PM.

  2. #2
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: How to use VBA LOOP to sum categories into a Cell

    I solved with a simple pivot table if you like.
    Attached Files Attached Files

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How to use VBA LOOP to sum categories into a Cell

    Hello jdcortez,

    Since you requested a VBA solution, here is one way that works quickly. The output goes to "Sheet2" starting in row 1, columns "A:C".

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: How to use VBA LOOP to sum categories into a Cell

    VBA
    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    09-06-2017
    Location
    portland, oregon
    MS-Off Ver
    2016
    Posts
    33

    Re: How to use VBA LOOP to sum categories into a Cell

    @jindon thank you for your solution!

  6. #6
    Registered User
    Join Date
    09-06-2017
    Location
    portland, oregon
    MS-Off Ver
    2016
    Posts
    33

    Re: How to use VBA LOOP to sum categories into a Cell

    @jindon is there a way to match the office names, and if the office name does not appear then skip to next office? i have uploaded your WB on have illustrated on sheet4
    Attached Files Attached Files

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: How to use VBA LOOP to sum categories into a Cell

    I'm not with my pc at the moment.

    I will respond when I get back.

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: How to use VBA LOOP to sum categories into a Cell

    Change to
    Please Login or Register  to view this content.
    Note : Office 1 will not show due to "Office1" vs "Office 1", missing a sapce before 1, should be identical.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    09-06-2017
    Location
    portland, oregon
    MS-Off Ver
    2016
    Posts
    33

    Re: How to use VBA LOOP to sum categories into a Cell

    @jindon Thank you for all your help! Last question I have when you get a moment. How do I change your second code if my data starts in a different range, say "Office names" started in $A8 and "Totals" started in $H8, these include headers so the actual raw data would be in $A9 and $H9

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: How to use VBA LOOP to sum categories into a Cell

    Fully depends on other rows/columns, so need to see your exact data layouts and you should mention this in your first post.

  11. #11
    Registered User
    Join Date
    09-06-2017
    Location
    portland, oregon
    MS-Off Ver
    2016
    Posts
    33

    Re: How to use VBA LOOP to sum categories into a Cell

    @jindon uploaded a WB, please don't mind the misc data, it is part of my data just cant display certain stuff. The only difference is just the position of the rows / coulumns
    Attached Files Attached Files

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: How to use VBA LOOP to sum categories into a Cell

    Only if you have row 7 blank in sheet2,
    Please Login or Register  to view this content.

+ 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. Chart from Categories with Sub-Categories
    By Chris Nolen in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 06-06-2017, 09:49 AM
  2. Loop Across Columns If Blank Cell Loop Down Rows
    By flindy87 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-05-2014, 10:22 AM
  3. Replies: 1
    Last Post: 05-15-2013, 06:55 AM
  4. [SOLVED] If names appears in range count and enter number in another cell. Split into categories
    By marsham in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-18-2013, 06:18 PM
  5. Replies: 0
    Last Post: 07-22-2011, 03:51 PM
  6. Grouping categories within categories
    By mju4t in forum Excel General
    Replies: 1
    Last Post: 11-03-2010, 02:41 PM
  7. Categories and Sub-Categories in Column Charts
    By theoneness in forum Excel General
    Replies: 2
    Last Post: 11-28-2009, 10:05 PM

Tags for this Thread

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