+ Reply to Thread
Results 1 to 8 of 8

Help to make VBA sort, summarize and paste data into desired order/grouping

  1. #1
    Registered User
    Join Date
    09-22-2014
    Location
    Denmark
    MS-Off Ver
    2010
    Posts
    4

    Help to make VBA sort, summarize and paste data into desired order/grouping

    Hi

    I'm fairly new to writing code in VBA, and is currently trying to replicate some previous Excel-work using VBA. I'm looking for either a hint to how I can write the wished procedures most effectively, or where I can find tutorials and learning material, that could lead me in the right direction. Any help is appreciated.

    Problem:

    I'm trying to figure out a way to sort my raw data into the required format of my budget. This requires me to do following sorting into groups by size and summarize values for these groups as well as paste values for the wanted rows and grouping.

    I wish make a sheet looking like the sheet "Budget" in the attached file. The raw data is listed in the sheet "Data"
    The grouping is based on Descending sort of "Current_value" into following groups
    1: "Name_org" (biggest organisation first)
    2: subgroup: "Region" (Biggest region withing organisation)

    *It need to summarize the values of "Previous_Value" and "Current_Value" for these groups

    *It should only paste values from rows, where either "Current_Value" and "Previous_Value" > 0

    *If "Current_Value" > 0 then location is included, otherwise it is left out

    I expect to use the procedure on data with around 300-500 rows.
    Attached Files Attached Files

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,958

    Re: Help to make VBA sort, summarize and paste data into desired order/grouping

    The macro recorder can get you through most of the first part - the sorting. I recorded a macro to do just that and I left it in the code. The subroutine below it is the same macro showing how I modified it to work for a more general case.

    The Summarize subroutine had to be built from scratch, but is documented.
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Registered User
    Join Date
    09-22-2014
    Location
    Denmark
    MS-Off Ver
    2010
    Posts
    4

    Re: Help to make VBA sort, summarize and paste data into desired order/grouping

    Thanks.

    The sorting seems to work nicely. Unfortunately I can't see the summations in the summary sheet?

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,958

    Re: Help to make VBA sort, summarize and paste data into desired order/grouping

    What kind of summations should there be? The summary sheet shows all lines that have either a current or previous value and if the current value is zero, the location is blank. It think this is what the requirement stated.

  5. #5
    Registered User
    Join Date
    09-22-2014
    Location
    Denmark
    MS-Off Ver
    2010
    Posts
    4

    Re: Help to make VBA sort, summarize and paste data into desired order/grouping

    That makes sense - I really appreciate the work done. Ideally I wanted it to make subtotals for current and previous values on to parameters "Name_org" and "Region".

  6. #6
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,958

    Re: Help to make VBA sort, summarize and paste data into desired order/grouping

    Doh! Got it. Try using a pivot table:
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    09-22-2014
    Location
    Denmark
    MS-Off Ver
    2010
    Posts
    4

    Re: Help to make VBA sort, summarize and paste data into desired order/grouping

    Awesome. The subtotal command also does the job nicely. I'll see if I can find a way of integrating it in the module you wrote - so it's all in one procedure.

  8. #8
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,958

    Re: Help to make VBA sort, summarize and paste data into desired order/grouping

    Probably the easiest thing to do is call them both from the same procedure
    Please Login or Register  to view this content.
    Otherwise you might have to reconcile some variables.

+ 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. [SOLVED] macro to grouping data and sort
    By oeyandyprawira in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-28-2015, 05:23 AM
  2. Replies: 1
    Last Post: 02-26-2013, 05:07 AM
  3. Replies: 4
    Last Post: 11-20-2012, 06:00 PM
  4. Excel 2007 : Data Sort with Two Row Grouping?
    By jisbell5 in forum Excel General
    Replies: 5
    Last Post: 09-13-2011, 03:31 PM
  5. Set copied data from closed workbook, paste into desired location.
    By Kenji in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-28-2009, 11:28 AM
  6. Replies: 1
    Last Post: 10-11-2005, 01:05 PM
  7. [SOLVED] Pls. reply Sort Data and copy to next coulmn when sort order chang
    By shital shah in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-19-2005, 10:05 AM

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