Hi,
Try this
Sub GroupAtBolds()
Dim i As Long
Dim lFirstInGroup As Long
Dim lLastInGroup As Long
i = 1
Do While Not (Range("A" & i) = "" And Range("A" & i + 1) = "")
'Test 1: see if the current line is blank.
If Trim(Range("A" & i)) = "" Then
lFirstInGroup = 0
lLastInGroup = 0
'test 2: see if the fontstyle is "Bold" (doing this second
'in case the empty cell is formatted as "Bold", also)
'Use the previous row as the last row in the group.
ElseIf Range("A" & i).Font.FontStyle = "Bold" Then
lLastInGroup = i - 1
'if neither of the above conditions are true, and there isn't a
'current FirstRow for the group found, then this row must be the
'first row in the new group.
ElseIf lFirstInGroup = 0 Then
lFirstInGroup = i
End If
'If we have both a first row and last row identified for the group,
'then we can group it.
If lFirstInGroup <> 0 And lLastInGroup <> 0 Then
Rows(lFirstInGroup & ":" & lLastInGroup).Group
End If
i = i + 1
Loop
End Sub
Bookmarks