Try this code on 1 worksheet
Option Explicit
Sub create_groups()
Dim lrow As Long, i As Long, startrange As Long, endrange As Long
Application.ScreenUpdating = False
With Worksheets("Sheet1")
lrow = .Range("A" & .Rows.Count).End(xlUp).Row
For i = 2 To lrow
If .Range("A" & i).Value = "" And .Range("A" & i - 1).Value <> "" Then
startrange = i
ElseIf .Range("A" & i).Value = "" And .Range("A" & i + 1).Value = "" Then
endrange = i + 1
ElseIf .Range("A" & i).Value = "" And .Range("A" & i + 1).Value <> "" Then
endrange = i
.Rows(startrange & ":" & endrange).Group
End If
Next i
End With
Application.ScreenUpdating = True
End Sub
If its working fine, i can help you in making it work for other worksheets too. Also, please put some text in the row after the last row of data so that the macro will group that set of data as well. Once you test it, you will realise that the last set of rows are not being grouped. Once you put some text such as "End" it should work.
Bookmarks