Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Determine the number of outline levels using vba

And this version also works on a sheet with no outline.
--
Jim Cone
San Francisco, USA
http://www.officeletter.com/blink/specialsort.html


Sub HowManyLevels_R1()
'Determines the number of outline levels (8 or less)
'Jim Cone - San Francisco, USA - October 2006
Dim lngNewCount As Long
Dim lngOldCount As Long
Dim N As Long
Dim rngArea As Excel.Range
Dim rngVisible As Excel.Range

N = 8 ' Throws error on xl2002 if 8.
lngOldCount = ActiveSheet.UsedRange.Rows.Count

Do
ActiveSheet.Outline.ShowLevels rowlevels:=N
Set rngVisible = ActiveSheet.UsedRange.SpecialCells(xlCellTypeVisib le)
For Each rngArea In rngVisible.Areas
lngNewCount = lngNewCount + rngArea.Rows.Count
Next
'The first instance where rows are hidden.
If lngNewCount < lngOldCount Then
MsgBox N + 1 & " Outline levels on sheet. "
Exit Do
Else
'Reset counters
lngOldCount = lngNewCount
lngNewCount = 0
End If
'Set to the next level
N = N - 1
Loop Until N < 0
If N < 0 Then MsgBox "No outline levels on sheet. "

Set rngArea = Nothing
Set rngVisible = Nothing
End Sub

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
Outline(grouping) more than 8 levels dk96m Excel Discussion (Misc queries) 1 October 26th 09 06:10 PM
Subtotal error to expand Outline Levels Michelle Excel Discussion (Misc queries) 1 October 4th 07 12:31 AM
"Data Group and Outline Group" feature Limited to 8 levels MarekMG Excel Discussion (Misc queries) 3 May 25th 07 06:12 PM
Determining number of Outline levels Keith Excel Programming 1 February 7th 06 07:14 PM
outline...hide levels icebreaker914 Excel Programming 1 June 24th 05 08:05 AM


All times are GMT +1. The time now is 12:09 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"