Sub groupRows()
Dim row1 As Integer, row2 As Integer
Dim colC As Integer
row2 = 1
colC = Cells(Rows.Count, 3).End(xlUp).Row
Do
row1 = row2
While Cells(row1, 3).Value <> "-"
row1 = row1 + 1
If row1 > colC Then Exit Do
Wend
row2 = row1 + 1
While Cells(row2, 3).Value = "-"
row2 = row2 + 1
Wend
Range(Cells(row1, 3), Cells(row2 - 1, 3)).EntireRow.Group
Loop
End Sub
Try this:
Code:Sub groupRows() Dim row1 As Integer, row2 As Integer Dim colC As Integer row2 = 1 colC = Cells(Rows.Count, 3).End(xlUp).Row Do row1 = row2 While Cells(row1, 3).Value <> "-" row1 = row1 + 1 If row1 > colC Then Exit Do Wend row2 = row1 + 1 While Cells(row2, 3).Value = "-" row2 = row2 + 1 Wend Range(Cells(row1, 3), Cells(row2 - 1, 3)).EntireRow.Group Loop End Sub
?"'" & Activecell.Value & "'"