+ Reply to Thread
Results 1 to 16 of 16

VBA Macro for Grouping based on Critria

  1. #1
    Registered User
    Join Date
    07-20-2011
    Location
    Missouri, USA
    MS-Off Ver
    Excel 2007
    Posts
    36

    VBA Macro for Grouping based on Critria

    I found this VBA code but it doesn't work because it doesn't select the group and I cannot figure how to make it work.

    Please Login or Register  to view this content.

    The code here should be group each set of Italics together.
    Here is an example of what it should be grouping:

    A B C D E F

    Alaska ITEM1
    Alaska ITEM2
    Alaska ITEM3
    COLD EAST ITEM1
    COLD EAST ITEM2
    COLD EAST ITEM3
    Last edited by popfan; 12-16-2011 at 05:29 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA Macro for Grouping based on Critria

    I believe you will need to have your macro insert blank rows between each group to get them to behave independently. Is that ok?
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA Macro for Grouping based on Critria

    This macro would do that:
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    07-20-2011
    Location
    Missouri, USA
    MS-Off Ver
    Excel 2007
    Posts
    36

    Re: VBA Macro for Grouping based on Critria

    This is not quite working the way you wanted it to. I am going to try to attach a spreadsheet to show you what I am working with.

    http://mediafire.com/?a7mz6h5ah222a3i

    Sorry about the size it has some macro I am using to format the file to the correct look. I just need the Italic parts grouped together. I can do the rest.

    TOTAL should not be Italicized
    Last edited by popfan; 12-14-2011 at 11:32 AM.

  5. #5
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: VBA Macro for Grouping based on Critria

    Would filtering your data work? Use DATA>FILTER and in column F, select Promo and Regular.

  6. #6
    Registered User
    Join Date
    07-20-2011
    Location
    Missouri, USA
    MS-Off Ver
    Excel 2007
    Posts
    36

    Re: VBA Macro for Grouping based on Critria

    Not really, because that would cause all my formatting to end up being jacked up, i think. I need to the macro to select the row based on the Italics (mostly like easier then selected each set of promo and regular individually) and create at group at each set.

  7. #7
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: VBA Macro for Grouping based on Critria

    Might I suggest using Pivot Tables? Attached is a copy of a PT version of your table.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    07-20-2011
    Location
    Missouri, USA
    MS-Off Ver
    Excel 2007
    Posts
    36

    Re: VBA Macro for Grouping based on Critria

    I would do this but, I have calculated fields that are based on totals and subtotal from the Sale Area. I removed them from the sheet for speed purposes and pivot tables are a big pain when have to add in calculations to each area.

  9. #9
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: VBA Macro for Grouping based on Critria

    popfan,

    I used this on your example after removing all the formatting. See attached file.
    Please Login or Register  to view this content.

  10. #10
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: VBA Macro for Grouping based on Critria

    Macro in previous file crashed. Try this one.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    07-20-2011
    Location
    Missouri, USA
    MS-Off Ver
    Excel 2007
    Posts
    36

    Re: VBA Macro for Grouping based on Critria

    Perfect. How do I add calculation into Column 12 with the formula = J(row here)/K(Row here) - 1 into the subtotal area?

  12. #12
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: VBA Macro for Grouping based on Critria

    Not sure what you mean by Row Here, but to include other columns into the subtotals, change the 2nd TotalList array. I.e. TotalList:=Array(7, 10, 11)

  13. #13
    Registered User
    Join Date
    07-20-2011
    Location
    Missouri, USA
    MS-Off Ver
    Excel 2007
    Posts
    36

    Re: VBA Macro for Grouping based on Critria

    I figured out the summing in an array. But now, need to calculate the subtotal area with a the formula = J(cell from cell subtotal)/I(cell from cell subtotal) -1 or how to copy a value from the cell above into the subtotal row. Example - I need Sale Area to put into each Subtotal area (red font)
    This is the normal out put
    ALASKA 152 0 ALASKA - 0 PROMO 237.49 77.73
    ALASKA 152 0 ALASKA - 0 REGULAR 279.19 241.74
    ALASKA - 0 Total 516.68 319.47
    ALASKA Total 516.68 319.47

    This is what I am looking for
    Sale Area Region SubRegion Region Name Promo Current Sales $ Previous Sales
    ALASKA 152 0 ALASKA - 0 PROMO 237.49 77.73
    ALASKA 152 0 ALASKA - 0 REGULAR 279.19 241.74
    ALASKA ALASKA - 0 Total 516.68 319.47
    ALASKA Total 516.68 319.47
    Last edited by popfan; 12-15-2011 at 01:42 PM.

  14. #14
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: VBA Macro for Grouping based on Critria

    Try modifying these two lines...
    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    07-20-2011
    Location
    Missouri, USA
    MS-Off Ver
    Excel 2007
    Posts
    36

    Re: VBA Macro for Grouping based on Critria

    Quote Originally Posted by dangelor View Post
    Try modifying these two lines...
    Please Login or Register  to view this content.

    Not quite what I was referring to. See Attached sheet - take a look at the notes added. I would like to see if I can add a macro to generate those formulas.
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    07-20-2011
    Location
    Missouri, USA
    MS-Off Ver
    Excel 2007
    Posts
    36

    Re: VBA Macro for Grouping based on Critria

    I think I found my answer:

    Please Login or Register  to view this content.

    Thanks all for your help!
    Last edited by popfan; 12-16-2011 at 05:29 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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