Quick VBA Macro to group rows based on cell values - Outline Style

Dedonovan

New Member
Joined
Aug 22, 2013
Messages
7
Hi Everyone,
I'm attempting to reengineer a similar post about grouping columns but I want to group rows. Below is the original thread with an excellent response from @Crystalyzer:
Group by Column Thread

What I want to do is group rows of sub-accounts within a parent subtotal row and Grand Total. Below is what I would like the final output to look like. Starting point is identical without the groups.
1678310353435.png


This is the current code I have so far that loops through the rows and appears to identify the correct Subtotal rows but doesn't group the rows. I appreciate any help. Thank you to @Crystalyzer for getting me this far.

Code:
Sub GroupRows()
    Dim i As Long, grpRowStart As Long, grpRowEnd As Long
    Dim strtRow As Long, endRow As Long
 
    If Range("B2") = "" Then
        strtRow = Range("B2").End(xlDown)
    Else
        strtRow = 1
    End If
 
    endCol = Cells(Rows.Count, "B").End(xlUp).Row

     
    For i = strtRow To endRow
        If InStr(2, Cells(i, 2), "F_6") = 0 Then
            If grpRowStart = 0 Then grpRowStart = i
            grpRowEnd = i
        Else
            If grpRowStart <> 0 And grpRowEnd <> 0 Then
                Range(Cells(grpRowStart, 2), Cells(grpRowEnd, 2)).Rows.Group
                grpRowStart = 0
                grpRowEnd = 0
            End If
        End If
     
    Next

End Sub

Thanks in advance for any input!!
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top