ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to Outline based on Indent Level (https://www.excelbanter.com/excel-programming/387386-macro-outline-based-indent-level.html)

[email protected]

Macro to Outline based on Indent Level
 
I have a worksheet with column B being titles that are indented to
outline the list (I even have the indent level a column). I would
like to outline this with VBA with a macro, so I can hide and show the
details as necessary. Can anyone help me with how to set up the loops
to search and determine the first and last rows of the group. My
summary row is above.

I know how to group and outline rows manually and have recorded it.
The issue is I want to be able to automate the process for future
versions. I also add and delete rows which causes outlining errors.

Example
Row Description indent LevelMore columns
1 Desc 1 0
1 Desc 1 1
1 Desc 1 2
1 Desc 1 2
1 Desc 1 1
1 Desc 1 2
1 Desc 1 2
1 Desc 1 2
1 Desc 1 0
1 Desc 1 1
1 Desc 1


joel

Macro to Outline based on Indent Level
 
Hope this helps. You can remove idents by use negaive numbers for
identlevel. You will get an error 1004 if you go under 1. If the ident
level is two you can one use identlevel -1 (-2 will give the error).

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 4/13/2007 by Joel Warburg
'

'Ident text
For RowCount = 1 To 10

Range("A" & CStr(RowCount)).InsertIndent RowCount

Next RowCount

'read ident level
For RowCount = 1 To 10

MsgBox (CStr(Range("A" & CStr(RowCount)).IndentLevel))

Next RowCount

End Sub


" wrote:

I have a worksheet with column B being titles that are indented to
outline the list (I even have the indent level a column). I would
like to outline this with VBA with a macro, so I can hide and show the
details as necessary. Can anyone help me with how to set up the loops
to search and determine the first and last rows of the group. My
summary row is above.

I know how to group and outline rows manually and have recorded it.
The issue is I want to be able to automate the process for future
versions. I also add and delete rows which causes outlining errors.

Example
Row Description indent LevelMore columns
1 Desc 1 0
1 Desc 1 1
1 Desc 1 2
1 Desc 1 2
1 Desc 1 1
1 Desc 1 2
1 Desc 1 2
1 Desc 1 2
1 Desc 1 0
1 Desc 1 1
1 Desc 1



Carlg

Macro to Outline based on Indent Level
 
Joel,

Sorry for the confusion. the example below is what I already have. I
want to be able to use the "Outline" ability of Excel to hide an show
the subordanate rows. To the left of the row numbers there are + & -
the show groups of rows. I want to group them with VBA. I want to
keep the indenting.

Example of current sheet. I want to group the 2's below the 1s and
the 1s below the 0. I actually have 4 levels of indents. I have
about 300 rows therefore speed is a concern.
Row Description indent LevelMore columns
1 Desc 0
2 Desc 1
3 Desc 2
4 Desc 2
5 Desc 1
6 Desc 2
7 Desc 2
8 Desc 2
9 Desc 0
10 Desc 1
11 Desc 1


On Apr 13, 11:54 am, Joel wrote:
Hope this helps. You can remove idents by use negaive numbers for
identlevel. You will get an error 1004 if you go under 1. If the ident
level is two you can one use identlevel -1 (-2 will give the error).

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 4/13/2007 by Joel Warburg
'

'Ident text
For RowCount = 1 To 10

Range("A" & CStr(RowCount)).InsertIndent RowCount

Next RowCount

'read ident level
For RowCount = 1 To 10

MsgBox (CStr(Range("A" & CStr(RowCount)).IndentLevel))

Next RowCount

End Sub

" wrote:
I have a worksheet with column B being titles that are indented to
outline the list (I even have the indent level a column). I would
like to outline this with VBA with a macro, so I can hide and show the
details as necessary. Can anyone help me with how to set up the loops
to search and determine the first and last rows of the group. My
summary row is above.


I know how to group and outline rows manually and have recorded it.
The issue is I want to be able to automate the process for future
versions. I also add and delete rows which causes outlining errors.


Example
Row Description indent LevelMore columns
1 Desc 1 0
1 Desc 1 1
1 Desc 1 2
1 Desc 1 2
1 Desc 1 1
1 Desc 1 2
1 Desc 1 2
1 Desc 1 2
1 Desc 1 0
1 Desc 1 1
1 Desc



joel

Macro to Outline based on Indent Level
 
I provided the code you asked for so in the future you can automatically add
the identing. You basically want to either
1) hide every row with an ident of 2 or more.
2) Or unhide all rows.


"Carlg" wrote:

Joel,

Sorry for the confusion. the example below is what I already have. I
want to be able to use the "Outline" ability of Excel to hide an show
the subordanate rows. To the left of the row numbers there are + & -
the show groups of rows. I want to group them with VBA. I want to
keep the indenting.

Example of current sheet. I want to group the 2's below the 1s and
the 1s below the 0. I actually have 4 levels of indents. I have
about 300 rows therefore speed is a concern.
Row Description indent LevelMore columns
1 Desc 0
2 Desc 1
3 Desc 2
4 Desc 2
5 Desc 1
6 Desc 2
7 Desc 2
8 Desc 2
9 Desc 0
10 Desc 1
11 Desc 1


On Apr 13, 11:54 am, Joel wrote:
Hope this helps. You can remove idents by use negaive numbers for
identlevel. You will get an error 1004 if you go under 1. If the ident
level is two you can one use identlevel -1 (-2 will give the error).

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 4/13/2007 by Joel Warburg
'

'Ident text
For RowCount = 1 To 10

Range("A" & CStr(RowCount)).InsertIndent RowCount

Next RowCount

'read ident level
For RowCount = 1 To 10

MsgBox (CStr(Range("A" & CStr(RowCount)).IndentLevel))

Next RowCount

End Sub

" wrote:
I have a worksheet with column B being titles that are indented to
outline the list (I even have the indent level a column). I would
like to outline this with VBA with a macro, so I can hide and show the
details as necessary. Can anyone help me with how to set up the loops
to search and determine the first and last rows of the group. My
summary row is above.


I know how to group and outline rows manually and have recorded it.
The issue is I want to be able to automate the process for future
versions. I also add and delete rows which causes outlining errors.


Example
Row Description indent LevelMore columns
1 Desc 1 0
1 Desc 1 1
1 Desc 1 2
1 Desc 1 2
1 Desc 1 1
1 Desc 1 2
1 Desc 1 2
1 Desc 1 2
1 Desc 1 0
1 Desc 1 1
1 Desc





All times are GMT +1. The time now is 06:48 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com