+ Reply to Thread
Results 1 to 13 of 13

Macro to Group Rows with Zeros in Multiple Columns

  1. #1
    Registered User
    Join Date
    03-06-2013
    Location
    Texas, USA
    MS-Off Ver
    Excel 2010
    Posts
    24

    Macro to Group Rows with Zeros in Multiple Columns

    I've search multiple posts trying to find this solution only to have the code not work for me. I've found several posts that group/hide and have tried to tweak the macro to work for me, but I'm just not that familiar with these commands and am having no luck.
    I have a workbook with multiple sheets for financial reporting each with multiple columns for months/year-to-date info. All of the sheets pull data from another master sheet within the workbook and then each sheet is consolidated to another sheet. Some of the sheets have rows which contain all zeros. I'd like to create a macro that will first ungroup/unhide all rows, then group (or hide) all rows that contain zeros in all of the data columns. I'd like to run the macro and have it perform this action on all of the sheets except the master sheets.
    Attached is an example of the workbook. The master data is exported from a financial program and pasted into the master worksheets. The data from the master sheets flow to each individual sheet and to the consolidated. Any help would be greatly appreciated!


    ZeroRows.xlsm

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Macro to Group Rows with Zeros in Multiple Columns

    Any reason why you want to first unhide / ungroup all the rows and then hide?

    Do you want the hide/ unhide to happen on the click of a button?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    03-06-2013
    Location
    Texas, USA
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Macro to Group Rows with Zeros in Multiple Columns

    Thanks for the reply! This spreadsheet will be updated each month and there may be rows that contain non-zero values that were previously hidden. I figured if I unhide/ungroup all of the rows first, that would take care of them when we did the re-hide/re-group. I'm open to suggestions!

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Macro to Group Rows with Zeros in Multiple Columns

    Ok, that sounds fine.

  5. #5
    Registered User
    Join Date
    03-06-2013
    Location
    Texas, USA
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Macro to Group Rows with Zeros in Multiple Columns

    Anybody have any thoughts on a solution for this macro? Any help would be appreciated!

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Macro to Group Rows with Zeros in Multiple Columns

    Do you want the hide / unhide to happen at the click of a button or once values are updated (maybe via formulae) in the cells?

  7. #7
    Registered User
    Join Date
    03-06-2013
    Location
    Texas, USA
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Macro to Group Rows with Zeros in Multiple Columns

    The click of a button would be perfect!

  8. #8
    Valued Forum Contributor
    Join Date
    11-20-2012
    Location
    Seattle, WA USA
    MS-Off Ver
    Excel 2010
    Posts
    597

    Re: Macro to Group Rows with Zeros in Multiple Columns

    I use this code to auto group based on columns being 0 (only if all columns = 0

    Please Login or Register  to view this content.

  9. #9
    Valued Forum Contributor
    Join Date
    11-20-2012
    Location
    Seattle, WA USA
    MS-Off Ver
    Excel 2010
    Posts
    597

    Re: Macro to Group Rows with Zeros in Multiple Columns

    self quote: we need more details on which sheets are being pulled to where so we can help you with the rest of the macro
    never mind i missed that part in the post
    Last edited by scott.s.fower; 04-22-2013 at 09:08 PM.

  10. #10
    Valued Forum Contributor
    Join Date
    11-20-2012
    Location
    Seattle, WA USA
    MS-Off Ver
    Excel 2010
    Posts
    597

    Re: Macro to Group Rows with Zeros in Multiple Columns

    i over thought the process try this:

    Please Login or Register  to view this content.
    you can add it to a macro triggered by a button, it currently just does it for the selected sheet but you could do it for all non control sheets

  11. #11
    Registered User
    Join Date
    03-06-2013
    Location
    Texas, USA
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Macro to Group Rows with Zeros in Multiple Columns

    Quote Originally Posted by scott.s.fower View Post
    i over thought the process try this:

    sumrng = Range(Range("A" & Lrow), Range("Z" & Lrow)).Address '<--defines range for the sum formula in the next line
    Range("ZZ" & Lrow).Formula = "=Sum(" & sumrng & ")" '<--will sum A:Z in the row
    If Range("ZZ" & Lrow).Value = 0 Then Range("ZZ" & Lrow).EntireRow.group '<--groups the row if it sums to 0

    Thanks for the reply Scott! If I read this correctly, it will sum each row and then hide the row if it susm to zero. The problem I see is that if one month (column) had an entry and then another month (column) had a negative entry for the same amount. My understanding is that this macro would hide the row, but then my visible rows in each column would not add up because some of the data is hidden. If there's data in the column, I would need it to show up. Am I reading this correctly?
    Last edited by arlu1201; 04-29-2013 at 08:10 AM.

  12. #12
    Valued Forum Contributor
    Join Date
    11-20-2012
    Location
    Seattle, WA USA
    MS-Off Ver
    Excel 2010
    Posts
    597
    Yeah, didn't think about that ill see what I can figure out to resolve that

  13. #13
    Valued Forum Contributor
    Join Date
    11-20-2012
    Location
    Seattle, WA USA
    MS-Off Ver
    Excel 2010
    Posts
    597

    Re: Macro to Group Rows with Zeros in Multiple Columns

    here's the update, it uses a second helper column AAA to count for any values less than 0, if there are any then it won't group even if it sums to 0 in column ZZ
    let me know if it works as you desire

    *edit*
    added the lines:
    .Cells.EntireRow.Hidden = False (so you dont have to manually unhide the cells)
    .Cells.ClearOutline (so you can just run the macro when the data changes with out having to manually clear the outline)
    Please Login or Register  to view this content.
    Last edited by scott.s.fower; 04-25-2013 at 05:57 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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