Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Use VBA to find, Group, Ungroup rows

Hi, I have a worksheet with nested groups of rows, e.g., rows 1 to 10 are
grouped and within that group rows 5 to 10 are grouped. I'm trying to write
code that will find the number of groups on the page and which rows they
apply to so I can automate the insertion of new groups of rows between
others. All I can find in Excel VBA Help is the basic syntax for the
Group/Ungroup command. Can anyone suggest a resource for more advanced
use/control of these?

Any help is deeply appreciated,
Don
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Use VBA to find, Group, Ungroup rows

I don't know of a site where there is extensive documentation on it, but it
pretty much boils down to looping through the rows and checking the
outlinelevel property.

Here is code I posted a while ago that determines what the current outline
level showing is:

Public Function Level(Sh As Worksheet)
Dim visRows As Range
Dim rw As Range
Dim maxLevel As Integer
Set visRows = Sh.UsedRange.SpecialCells(xlVisible)
Set visRows = Intersect(visRows, Sh.Columns(1)).EntireRow
maxLevel = 0
For Each rw In visRows
If rw.OutlineLevel <= maxLevel And maxLevel < 1 Then Exit For
If rw.OutlineLevel maxLevel Then maxLevel = rw.OutlineLevel
Next
Level = maxLevel
End Function

This would only be appropriate if setting the outline only through the
buttons. If it is being done manually, then there wouldn't be just one
level. In any event, this should give you some ideas.

--
Regards,
Tom Ogilvy



"donesquire" wrote:

Hi, I have a worksheet with nested groups of rows, e.g., rows 1 to 10 are
grouped and within that group rows 5 to 10 are grouped. I'm trying to write
code that will find the number of groups on the page and which rows they
apply to so I can automate the insertion of new groups of rows between
others. All I can find in Excel VBA Help is the basic syntax for the
Group/Ungroup command. Can anyone suggest a resource for more advanced
use/control of these?

Any help is deeply appreciated,
Don

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Use VBA to find, Group, Ungroup rows

Tom, I'll work through your example and try to apply it to my situation.

Thanks very much for your help and quick response,
Don


"Tom Ogilvy" wrote:

I don't know of a site where there is extensive documentation on it, but it
pretty much boils down to looping through the rows and checking the
outlinelevel property.

Here is code I posted a while ago that determines what the current outline
level showing is:

Public Function Level(Sh As Worksheet)
Dim visRows As Range
Dim rw As Range
Dim maxLevel As Integer
Set visRows = Sh.UsedRange.SpecialCells(xlVisible)
Set visRows = Intersect(visRows, Sh.Columns(1)).EntireRow
maxLevel = 0
For Each rw In visRows
If rw.OutlineLevel <= maxLevel And maxLevel < 1 Then Exit For
If rw.OutlineLevel maxLevel Then maxLevel = rw.OutlineLevel
Next
Level = maxLevel
End Function

This would only be appropriate if setting the outline only through the
buttons. If it is being done manually, then there wouldn't be just one
level. In any event, this should give you some ideas.

--
Regards,
Tom Ogilvy



"donesquire" wrote:

Hi, I have a worksheet with nested groups of rows, e.g., rows 1 to 10 are
grouped and within that group rows 5 to 10 are grouped. I'm trying to write
code that will find the number of groups on the page and which rows they
apply to so I can automate the insertion of new groups of rows between
others. All I can find in Excel VBA Help is the basic syntax for the
Group/Ungroup command. Can anyone suggest a resource for more advanced
use/control of these?

Any help is deeply appreciated,
Don

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
Data Group and Ungroup Rebecca Excel Discussion (Misc queries) 3 January 3rd 09 09:13 AM
group&ungroup fofomama Charts and Charting in Excel 0 August 23rd 07 04:22 PM
On protected Excel sheet users be able to group/ungroup rows/colum Oryssia Excel Worksheet Functions 2 June 6th 06 12:49 PM
Help with Group/Ungroup deacs Excel Discussion (Misc queries) 3 January 30th 06 04:29 PM
how do you group and ungroup rows or columns in new Excel? moocowcreamer Excel Worksheet Functions 2 November 17th 04 02:28 AM


All times are GMT +1. The time now is 02:16 AM.

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

About Us

"It's about Microsoft Excel"