Results 1 to 10 of 11

Thread: Group Pivot Data Based On Row Values In One Column

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    Try this

    Code:
    Sub Consolidator()
    
        Dim obj As Range
        
        'Since there is a possibility that there are already Outlines made in the used range, we'd want to ensure it is removed
        On Error Resume Next
        Do Until Err.Number <> 0
            Worksheets("Data").UsedRange.Rows.Ungroup'This is where we remove the outlining
        Loop
        Err.Clear: On Error GoTo 0: On Error GoTo -1'Clear up and reset the error handling
        For Each obj In Worksheets("Data").UsedRange.Columns(3).Cells.SpecialCells(xlCellTypeBlanks)'We use the specialcells method and pick only the blank cells, and then we loop through each blank cell
            If Not IsEmpty(obj.Offset(2)) Then'If the cell 2 rows below the blank cell is not empty, then that means there are at least 2 rows to be grouped, in which case End(xlDown) will take use to the last row for that section
                obj.Parent.Range(obj.Offset(1), obj.Offset(1).End(xlDown)).Rows.Group' so the section of the range that we want to group starts from the first cell below the blank cell, all the way down to the last cell in that group before the next blank, which can be located using End(xlDown) because there are at least 2 rows
            Else
                obj.Offset(1).Rows.Group'If the cell 2 rows below the blank cell is empty, we can assume that the section to be grouped has only 1 row, so we just group that row
            End If
    
        Next obj
        
    End Sub
    where "Data" is the name of the sheet where you have the data to be outlined. Change as suited.
    Last edited by Excel Fox; 10-09-2012 at 11:46 PM. Reason: Comments added
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

Similar Threads

  1. Replies: 3
    Last Post: 05-23-2013, 11:17 PM
  2. Replies: 17
    Last Post: 05-22-2013, 11:58 PM
  3. Offset based on Values in Column E
    By mrmmickle1 in forum Excel Help
    Replies: 7
    Last Post: 12-04-2012, 10:06 AM
  4. Autofill the data based on non blank cell in next row?
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 3
    Last Post: 11-29-2012, 04:16 PM
  5. Copy Row To A New Sheet If A Value Found In Adjacent Column
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 4
    Last Post: 08-17-2012, 05:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •