+ Reply to Thread
Results 1 to 28 of 28

Macro to extend row grouping to include blank row

  1. #1
    Registered User
    Join Date
    05-19-2009
    Location
    WA, USA
    MS-Off Ver
    Excel 2010 and Office 365
    Posts
    50

    Macro to extend row grouping to include blank row

    I had thought that we were able to upload spreadsheets here, but I can't figure out how to do it. There's an icon at the top of the topic options with a paperclip, but clicking that only pops up a small, empty, rectangular box underneath it. I can try to explain this without the spreadsheet, if necessary, but think it would be easier with the actual spreadsheet. If I'm not seeing how to upload a file, please let me know how to do it.

    I've got a spreadsheet where I would like to use a macro to add a blank row to an existing group of rows, until it encounters two blank rows. At that point, I would like the macro to stop.

    Basically, in the screenshots below ("before" on the left, "after" on the right), I would like the macro to start looking in cell B5, then continue down, looking for a blank cell in column B. If there are not two blank cells/rows together, I would like to extend the grouping down to include the single blank row. When it encounters two blank cells/rows, I would like the macro to do the grouping one more time, and then stop. So, in the screenshot, when it gets to cell B33, it will add row 33 to the group above, and then it will stop since cell B34 is also blank.

    Grouping.jpg Grouping (after).jpg

    Thanks for your help. You guys are great!!!
    Last edited by Styler001; 10-01-2017 at 02:42 PM. Reason: added "after" screenshot, clarified conditions of last grouping

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to extend row grouping to include blank row

    Here are the new instructions:

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

    *this will find your last row:

    Please Login or Register  to view this content.
    Last edited by xladept; 10-01-2017 at 12:53 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    05-19-2009
    Location
    WA, USA
    MS-Off Ver
    Excel 2010 and Office 365
    Posts
    50

    Re: Macro to extend row grouping to include blank row

    WOW! That was quick!

    I knew you guys were awesome!

    I've attached the spreadsheet.

    I'm not really all that good with programming macros...actually, I can't program them at all. Thankfully, Excel will record a macro for me. So, if you could provide the complete macro, I'd really appreciate the help.

    When I was doing this manually, I had reassigned Ctrl-Q to be my recorded macro. How would I go about adding your macro in place of mine as Ctrl-Q again?

    One mistake I made in my original post was that where two blank rows are found, the macro should stop.

    It should actually add the blank line to the group, and then stop because two blank rows have been found.

    I also added the "after" screenshot to my original post.
    Attached Files Attached Files

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to extend row grouping to include blank row

    Thanks for the rep!

    Is this what you want?

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-19-2009
    Location
    WA, USA
    MS-Off Ver
    Excel 2010 and Office 365
    Posts
    50

    Re: Macro to extend row grouping to include blank row

    Thanks again for the quick reply.

    I'm not sure if that's what I wanted or not. How do I get that to work in the spreadsheet?

    Sorry to be asking such stupid questions, but I've never worked with a "programmed" macro before.

  6. #6
    Registered User
    Join Date
    05-19-2009
    Location
    WA, USA
    MS-Off Ver
    Excel 2010 and Office 365
    Posts
    50

    Re: Macro to extend row grouping to include blank row

    as I said, I really don't have much of a clue as to how to incorporate this into Excel so it works.

    I searched for how to import a VBA macro, followed the directions, but when I run it, I get this...

    Attachment 541194

    The only thing that seems to change is the little bit at the top, above the column headers. Each time I run the macro, it just adds another line at the top and does nothing else that I can tell.

  7. #7
    Registered User
    Join Date
    05-19-2009
    Location
    WA, USA
    MS-Off Ver
    Excel 2010 and Office 365
    Posts
    50

    Re: Macro to extend row grouping to include blank row

    Well, as I said, I really don't have much of a clue as to how to incorporate this into Excel so it works.

    I searched for how to import a VBA macro, followed the directions, but when I run it, I get this...

    Grouping (after running macro).jpg

    The only thing that seems to change is the little bit at the top, above the column headers. Each time I run the macro, it just adds another line at the top and does nothing else that I can tell.

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to extend row grouping to include blank row

    Your attachment is invalid.

    Directions for running the routine(s) just supplied

    If you haven't used macros before you'll need to go to:
    File- options - trust center -trust center settings - macro settings ,
    the second option down (disable all macros with notification)

    Then - Copy the code to the clipboard

    Open your Workbook

    Press ALT + F11 to open the Visual Basic Editor.

    Select "Module" from the Insert menu

    Type "Option Explicit" then paste the code under it

    With the cursor between Sub and End Sub press F5 (F8 to Single Step)

    OR

    Press ALT + Q to close the code window.

    Press ALT + F8 then double click on the macro name


    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  9. #9
    Registered User
    Join Date
    05-19-2009
    Location
    WA, USA
    MS-Off Ver
    Excel 2010 and Office 365
    Posts
    50

    Re: Macro to extend row grouping to include blank row

    I don't understand why this isn't working. I tried it on the spreadsheet from the last screenshot above and it worked flawlessly.

    Then I tried it in the real workbook and it's doing what it was doing before I had your instructions.

    Here's the before shot on the left, and the after on the right.

    Grouping (before).jpg Grouping (after).jpg

    Notice the difference at the top, between the formula bar and the column headings.

    I've attached the spreadsheet, too.

    I don't know what to do at this point. I just can't figure out why it decided to work once, and then not again.
    Attached Files Attached Files

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to extend row grouping to include blank row

    That's what grouping does - did you want all the data grouped or just the first two columns.
    Is grouping what you want at all?

  11. #11
    Registered User
    Join Date
    05-19-2009
    Location
    WA, USA
    MS-Off Ver
    Excel 2010 and Office 365
    Posts
    50

    Re: Macro to extend row grouping to include blank row

    I wanted it grouped by rows as you can see in the the before and after screenshots in my original post. It should add that blank row to the group above.

  12. #12
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to extend row grouping to include blank row

    Have you clicked on the 1,2 both vertical and horizontal? And, is it what you want??

  13. #13
    Registered User
    Join Date
    05-19-2009
    Location
    WA, USA
    MS-Off Ver
    Excel 2010 and Office 365
    Posts
    50

    Re: Macro to extend row grouping to include blank row

    The horizontal groupings were already in place in the "before" shot. That's how the process at work that generates the spreadsheet groups them.

    Each time I ran the macro, it just added a vertical grouping...not what I wanted.

  14. #14
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to extend row grouping to include blank row

    Well then maybe:

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    05-19-2009
    Location
    WA, USA
    MS-Off Ver
    Excel 2010 and Office 365
    Posts
    50

    Re: Macro to extend row grouping to include blank row

    I feel like a complete moron because I can't completely understand what your code is supposed to be doing, so I can't even attempt trying to fix anything without more of your help.

    This has the basic idea...it groups a blank line at the very end. But it should be adding the blank line after each group to that same group.

    Right now, it's doing this...

    New Result.jpg


    When it should be doing this...

    Desired Result.jpg


    Notice that row 16 is now part of the PAC 127501 group, and row 20 is now part of the PAC 127901 group.

    The last group farther down the spreadsheet would now look like this with row 53 now being part of the PAC 3997801380 group, where the macro would now end.

    Last Group.jpg


    These are my grouping options in the "Outline" settings:

    Grouping Options.jpg

    I truly appreciate all the time you're spending on this. I just wish I knew alot more about this so I didn't have to come across as being so lame.
    Last edited by Styler001; 10-07-2017 at 11:43 PM.

  16. #16
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to extend row grouping to include blank row

    I'll try again tomorrow - and nobody's perfect!

  17. #17
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to extend row grouping to include blank row

    Well I've tried and had no luck - I'm submitting this problem to the Forum.

  18. #18
    Registered User
    Join Date
    05-19-2009
    Location
    WA, USA
    MS-Off Ver
    Excel 2010 and Office 365
    Posts
    50

    Re: Macro to extend row grouping to include blank row

    Quote Originally Posted by xladept View Post
    I'll try again tomorrow - and nobody's perfect!
    Well I've tried and had no luck - I'm submitting this problem to the Forum.
    Thanks, I do appreciate the help and all of your time, even if a solution wasn't found. Hopefully the forum can help.

  19. #19
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to extend row grouping to include blank row

    Hi Styler001
    Try this Code in the attached...
    Please Login or Register  to view this content.
    Attached Files Attached Files
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  20. #20
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Macro to extend row grouping to include blank row

    Groups have to be separated by an empty row.



  21. #21
    Registered User
    Join Date
    05-19-2009
    Location
    WA, USA
    MS-Off Ver
    Excel 2010 and Office 365
    Posts
    50

    Re: Macro to extend row grouping to include blank row

    Quote Originally Posted by snb View Post
    Groups have to be separated by an empty row.
    No, they don't. I've been manually doing what I was wanting this macro to do for a long time now, and it all works fine when I go about doing some sorting.

  22. #22
    Registered User
    Join Date
    05-19-2009
    Location
    WA, USA
    MS-Off Ver
    Excel 2010 and Office 365
    Posts
    50

    Re: Macro to extend row grouping to include blank row

    Quote Originally Posted by jaslake View Post
    Hi Styler001
    Try this Code in the attached...
    Hi, jaslake. That worked almost as I'd hoped. The only thing it needed to do was add one more blank line to the last group.

    I'm still unsure how I would go about making that change in your code.

    Also, I'm not sure if the process at work names the worksheet to something besides "Sheet1". If it did, I'm guessing that I'll just need to change that in "Set ws =" line, is that right?

  23. #23
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to extend row grouping to include blank row

    Hi Styler001

    Change the indicated Lines of Code...
    Please Login or Register  to view this content.

  24. #24
    Registered User
    Join Date
    05-19-2009
    Location
    WA, USA
    MS-Off Ver
    Excel 2010 and Office 365
    Posts
    50

    Re: Macro to extend row grouping to include blank row

    BEAUTIFUL!!!!!

    Worked like a charm!!!!!

    Thanks, jaslake. Reps added.

    Thanks, too, xladept, for all the time you spent with me.

    Solved!

  25. #25
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to extend row grouping to include blank row

    You're welcome...glad I could help. Thanks for the Rep.

  26. #26
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to extend row grouping to include blank row

    I've been playing with this ever since John posted the solution and I've found that this combination works rather handily. You needn't run Styler separately as I've called in within John's code:

    Please Login or Register  to view this content.
    Last edited by xladept; 10-08-2017 at 04:12 PM.

  27. #27
    Registered User
    Join Date
    05-19-2009
    Location
    WA, USA
    MS-Off Ver
    Excel 2010 and Office 365
    Posts
    50

    Re: Macro to extend row grouping to include blank row

    Thanks, xl.

  28. #28
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to extend row grouping to include blank row

    You're welcome hope I'm not fixing anything that's not broke

+ 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. Replies: 2
    Last Post: 05-29-2014, 05:03 AM
  2. [SOLVED] Editing a Macro to include multiple rows and include text formatting for leading zeros
    By missmea2005 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-04-2014, 09:50 AM
  3. [SOLVED] How to not include blank dates help please!
    By jennieS in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-14-2013, 02:00 PM
  4. How Does One Extend a Range to Include One Row of Data?
    By StevenM in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-07-2012, 11:02 AM
  5. [SOLVED] how can I extend my drop-down box length to include all the list?
    By sigeco in forum Excel General
    Replies: 4
    Last Post: 06-19-2006, 10:40 PM
  6. [SOLVED] How do you extend the number of blank columns in a worksheet?
    By mybicycleisgreat in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-05-2006, 11:45 AM
  7. [SOLVED] Re: If cell does not include @, then blank
    By Dave Peterson in forum Excel General
    Replies: 1
    Last Post: 01-13-2006, 04:56 PM

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