R
ryguy7272
I was working with the below code for a few weeks:
Sub Grp()
Dim lngRow As Long
Sheets("Sheet1").Select
For i = 10 To 0 Step -2
For lngRow = Cells(Rows.Count, "B").End(xlUp).Row To 9 Step -1
If Range("B" & lngRow) <> "" And Left(Range("B" & lngRow), i) = Space(i) Then
Range("B" & lngRow & ":B" & lngRow).Rows.Group
End If
Next lngRow
Next i
End Sub
It works great for grouping cells based on spaces in front of the cells (0,
2, 4, 6, 8, or 10 spaces). What I’m trying to do now is modify the code
above to group cells based on the IndentLevel.
I am trying to modify this now (to do grouping based on IndentLevel):
Sub Grp()
Dim lngRow As Long
Sheets("Sheet1").Select
For i = 6 To 0 Step -1
For lngRow = Cells(Rows.Count, "B").End(xlUp).Row To 2 Step -1
If Range("B" & lngRow).IndentLevel > 0 And Range("B" & lngRow).IndentLevel =
(i) Then
Range("B" & lngRow & ":B" & lngRow).Rows.Group
End If
Next lngRow
Next i
End Sub
All this code does though, is give me one giant grouping; no sub-groups.
Jacob Skaria was kind enough to give me some code a few days ago. When I
ran it, it seemed to work on a small sample, but on a larger sample it didn’t
group appropriately. Specifically, it always seems to miss the last grouping
in any group.
I’ve spent a couple of hours on this, and haven’t been able to figure it out
yet. Does anyone know how to do this grouping, and get the last group in a
list, so that it rolls up into the whole list appropriately?
Thanks,
Ryan---
Sub Grp()
Dim lngRow As Long
Sheets("Sheet1").Select
For i = 10 To 0 Step -2
For lngRow = Cells(Rows.Count, "B").End(xlUp).Row To 9 Step -1
If Range("B" & lngRow) <> "" And Left(Range("B" & lngRow), i) = Space(i) Then
Range("B" & lngRow & ":B" & lngRow).Rows.Group
End If
Next lngRow
Next i
End Sub
It works great for grouping cells based on spaces in front of the cells (0,
2, 4, 6, 8, or 10 spaces). What I’m trying to do now is modify the code
above to group cells based on the IndentLevel.
I am trying to modify this now (to do grouping based on IndentLevel):
Sub Grp()
Dim lngRow As Long
Sheets("Sheet1").Select
For i = 6 To 0 Step -1
For lngRow = Cells(Rows.Count, "B").End(xlUp).Row To 2 Step -1
If Range("B" & lngRow).IndentLevel > 0 And Range("B" & lngRow).IndentLevel =
(i) Then
Range("B" & lngRow & ":B" & lngRow).Rows.Group
End If
Next lngRow
Next i
End Sub
All this code does though, is give me one giant grouping; no sub-groups.
Jacob Skaria was kind enough to give me some code a few days ago. When I
ran it, it seemed to work on a small sample, but on a larger sample it didn’t
group appropriately. Specifically, it always seems to miss the last grouping
in any group.
I’ve spent a couple of hours on this, and haven’t been able to figure it out
yet. Does anyone know how to do this grouping, and get the last group in a
list, so that it rolls up into the whole list appropriately?
Thanks,
Ryan---