+ Reply to Thread
Results 1 to 6 of 6

VBA help with grouping of rows dynamically

  1. #1
    Registered User
    Join Date
    10-21-2009
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2007
    Posts
    3

    VBA help with grouping of rows dynamically

    Hi there

    I am having a problem with a VBA macro I am trying to write. All I want to do is check all rows in a worksheet and group rows from the last bold row to the next bold row.

    I seem to have the conditional logic correct, however, instead of grouping rows separately in each loop, it keeps joining them together.

    Can someone please tell me where I am going wrong?
    Please Login or Register  to view this content.
    Last edited by PeterLim; 10-22-2009 at 05:59 PM. Reason: Added Code Tags

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

    Re: VBA help with grouping of rows dynamically

    Hello PeterLim,

    Welcome to the Forum!

    To make your posts easier to read, copy, and edit please wrap your code. I did it for you this time. Here is how you can do it next time.

    How to wrap your Code
    1. Select all your code using the mouse.
    2. Click on the # icon on the toolbar in the Message window. This will automatically wrap the text you selected with the proper Code tags to create a Code Window in your post.

    Use the Bulletin Board Code Tags
    [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] at the end of the last line.


    To learn more about BB codes used in this forum, just click on the link below...

    Bulletin Board Codes Tags
    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!)

  3. #3
    Forum Contributor
    Join Date
    03-12-2009
    Location
    Calgary, Canada
    MS-Off Ver
    Excel 365
    Posts
    236

    Re: VBA help with grouping of rows dynamically

    What exactly does "group rows" mean to you?
    If you can't figure out how a formula works, try stepping through it using "Evaluate Formula" in the Formula Auditing menu item in the tools menu!

    If you want to see where your code went wrong, try stepping through it by clicking in the code and pressing F8 and watch as the magic happens!


    If you are happy with any of the results, please add to the contributor's reputation by clicking the star icon.

  4. #4
    Registered User
    Join Date
    10-21-2009
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: VBA help with grouping of rows dynamically

    Its also known as outlining in Excel. You can do it manually going to the Data Ribbon in Excel 2007 and pressing the Group button.

    Heres a paste from the help file:
    If you have a list (list: A series of rows that contains related data or a series of rows that you designate to function as a datasheet by using the Create List command.) of data that you want to group and summarize, you can create an outline of up to eight levels, one for each group. Each inner level, represented by a higher number in the outline symbols (outline symbols: Symbols that you use to change the view of an outlined worksheet. You can show or hide detailed data by pressing the plus sign, minus sign, and the numbers 1, 2, 3, or 4, indicating the outline level.) displays detail data (detail data. Use an outline to quickly display summary rows or columns, or to reveal the detail data for each group.

  5. #5
    Forum Contributor
    Join Date
    03-12-2009
    Location
    Calgary, Canada
    MS-Off Ver
    Excel 365
    Posts
    236

    Re: VBA help with grouping of rows dynamically

    PeterLim,

    Have you tried to do this manually? As far as I can see it is impossible to group anything that is not contiguous or in the words of Excel "The command you chose cannot be performed with multiple selections".

    Would it work for you to first go through and move all of the highlighted item's rows together?

    I have seen grouping before, but I still cannot think of any application for it, as I learn about it I'm sure it will become a new favorite though, thanks.

  6. #6
    Registered User
    Join Date
    10-21-2009
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: VBA help with grouping of rows dynamically

    Hi Everstrivin

    Yes I can easily do it manually. Just do each grouping one at a time. In my VBA code it actually works when I do a step through, but the problem is that instead of grouping from row 9 - 15 and then 16 to 22, it grouped 9-15 and then 9-22.

    Anyway, you helped me fixed my problem. I realised that grouping actually had to be set to 9-14 and 16-22 so all I needed to do was offset the check flags by 1 and it worked. Thanks!

    Heres the code if you were interested.

    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)

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