group/ungroup

M

meg99

using 2003.

Columns("F:H").Select
Selection.Columns.group
will group the colums so the user can easily hide/unhide
the columns
Columns("F:H").Select
Selection.Columns.ungroup
will ungroup the columns ONLY if the columns are
grouped. if the columns are not grouped and the "ungroup" command is
issued, an error results.

question - is there a way to capture the "grouped" status of a
spreadsheet?

meg99
 
D

Dave Peterson

You could use something like:

Option Explicit
Sub testme()

Dim myCol As Range
Dim myRng As Range
Dim IsGrouped As Boolean

Set myRng = ActiveSheet.Range("F:G")

IsGrouped = False
For Each myCol In myRng.Columns
If myCol.OutlineLevel > 1 Then
IsGrouped = True
Exit For
End If
Next myCol

If IsGrouped Then
myRng.Ungroup
End If

End Sub

But I might just ignore the error (if that's the only error that may possibly
occur):

on error resume next
Columns("F:H").Columns.ungroup
on error goto 0

The bad news with this method is that you could be ignoring an error that you
don't want to ignore--like if the worksheet is protected.
 

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