Macro to Outline based on Indent Level

C

carl.gentry

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
 
G

Guest

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
 
C

Carlg

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
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top