Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Grouping Based on Indent

This seems to work flawlessly! Thanks so much, Jacob, for seeing it through
to the end!!!
Ryan--

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Jacob Skaria" wrote:

Hi Ryan

Revised solution for grouping. Insert a new module and copy the below code.
Number of indent levels is not fixed however in the below code either you
change the upper bound of the array OR as in the previous solution you can
re-dimension it at run-time. But i assume it wont run to more than 10 indent
levels..I have tested with few test cases. Try and feedback...


Dim arrINT(10) As Long
Sub GroupbyIndexLevels2()
Dim lngRow As Long
Dim intCIL As Integer
Dim intPIL As Integer
For lngRow = 1 To Cells(Rows.Count, "B").End(xlUp).Row
intCIL = Range("B" & lngRow).IndentLevel
If intCIL 0 Then
If intCIL intPIL Then
arrINT(intCIL) = lngRow
ElseIf intCIL < intPIL Then
GroupRows2 intCIL, lngRow
End If
intPIL = intCIL
End If
Next lngRow
GroupRows2 1, lngRow
ActiveSheet.Outline.ShowLevels RowLevels:=1
End Sub

Sub GroupRows2(intIND As Integer, lngRow As Long)
Dim intTemp As Integer
For intTemp = intIND + 1 To UBound(arrINT)
If arrINT(intTemp) < 0 Then
Rows(arrINT(intTemp) & ":" & lngRow - 1).Group
arrINT(intTemp) = 0
End If
Next
End Sub


If this post helps click Yes
---------------
Jacob Skaria


"ryguy7272" wrote:

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 Im 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 didnt
group appropriately. Specifically, it always seems to miss the last grouping
in any group.

Ive spent a couple of hours on this, and havent 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---


--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Indent based on character length Scott Excel Discussion (Misc queries) 4 July 20th 09 04:36 AM
Indent based on Entry JSnow Excel Discussion (Misc queries) 1 September 11th 08 05:29 PM
Indent and format based on Col A CB Excel Programming 4 April 30th 08 09:32 PM
Macro to Outline based on Indent Level [email protected] Excel Programming 3 April 13th 07 08:30 PM
Excel VBA - Best way to indent one column based on another wrkoch Excel Programming 2 May 30th 04 01:25 PM


All times are GMT +1. The time now is 12:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"