VBA to group and sub group

glynn1969

Board Regular
Joined
Nov 24, 2018
Messages
80
Office Version
  1. 365
Platform
  1. Windows
Hello (firtsly apologies i cannot add a copy of my workbook as i am unable to update my computer) - so added images.

Essentially i have data in two columns (A and B) and would like to run macro to group these (and sub group) based on the values in column A - the workbook i have is forever changing were the sub service and service levels sit and runs for over 300 rows, so is very laborious to do manually.

I have spent time and managed to group the "Service" levels but am having great difficulty in adding the Sub Service grouping - see VBA below ( i am not precious about my code and am quite happy for you to pull this apart and re-write).


Sub group_rows()

Dim area As Range
Dim LR As Long
Dim rng As Range
LR = Cells(Rows.Count, 1).End(xlUp).Row
MsgBox LR
Application.ScreenUpdating = False

'calls macro to ungroup rows first
ungroup_rows

On Error Resume Next
With Range("A1:A" & LR)
.AutoFilter Field:=1, Criteria1:="<>Service*"
Set rng = .Resize(.Rows.Count - 1, 1).Offset(1, 0).SpecialCells(xlCellTypeVisible)
.AutoFilter
End With
On Error GoTo 0

If Not rng Is Nothing Then
For Each area In rng.Areas
area.EntireRow.Group
Next area
End If

Application.ScreenUpdating = True

End Sub

The data runs in sequential order with all services running in order. Really hope the pictures help.

TOTAL DATA

1593553344619.png


Grouped by Sub Service

1593553453011.png


Grouped further to Service

1593553515640.png
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,215,430
Messages
6,124,846
Members
449,194
Latest member
HellScout

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