Group and Outline in Excel

Posted on 2001-06-20
Last Modified: 2009-12-24
Hi all
I'm using Group and Outline in Excel 2000 to group some collumns using VBA ( Selection.Columns.Group ). My question is : How do I hide and show the grouped collumns using VBA. I tried recording a macro and got the following VBA code :
ExecuteExcel4Macro "SHOW.DETAIL(2,8,FALSE,,7)"
Excel 4 macro ???????
Is there no other code that I can use ? If not, can someone tell me the syntax of this code.

Question by:forsbom
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
LVL 13

Expert Comment

ID: 6209405
There is, at least for Excel 97.

a) Do you want to show/hide the details for an individual column ? If yes: Do you want a toggle ? If no: Display the level 1,2,3... for all columns ?

b) Do you have users using Excel 97 ? There is a bug I tried to report in vain to Microsoft which must be circumvented.
LVL 13

Expert Comment

ID: 6209431
Sub Peekaboo()
  'Toggles the show/hide of column 6
  With ActiveSheet.Columns(6)
     .ShowDetail = (.ShowDetail = False)
  End With
End Sub

Author Comment

ID: 6209475
Hi cri
Thanks It's just what I wanted.
Your previous question : Yes my users are using Excel 97! What's the bug and what do I need to do ?????

To Patch or not to Patch? That is the question!

Don't get caught out like thousands of others around the world in the recent Ransomware Fiasco!
- Why it's not a good idea to wait before Patching
- Sensible approaches to Patching discussed
- Add your feedback, comments and suggestions

LVL 13

Accepted Solution

cri earned 75 total points
ID: 6209605
The bug is that if you re-state ShowDetail=False for a column/row with _already_ hidden details, then VBA will crash. Doing this on for ShowDetails=True will be ignored.

Therefore, either:

a) Ensure you always know the show/hidden status


b) Use the Toggle above


c) If the show/hide is for all columns/rows use this command:
ActiveSheet.Outline.ShowLevels RowLevels:=0, ColumnLevels:=1


d) Use this auxiliary Sub:

Sub HideDetail(rngToHide As Range)
   'Necessary because Visual Basic Office 97(SR-2) has a bug:
   '"ShowDetail = False" should not be re-stated if already = False,
   'contrary to ShowDetail = True resp. VB of Excel 5.0

   With rngToHide
      If .ShowDetail = True Then
         .ShowDetail = False
         'Do absolutely nothing
      End If
   End With
End Sub

Sub test()
  With ActiveSheet
    HideDetail .Columns(6)
    HideDetail .Rows(16)
    MsgBox "Fasten your seat belts, will crash VBA"
    .Rows(16).ShowDetail = False
 End With
End Sub

Author Comment

ID: 6209617
Thanks cri!!
Great answer!

LVL 13

Expert Comment

ID: 6209783
ThAnk you. Does it crash in Excel 2000 too ?
LVL 13

Expert Comment

ID: 6210202
Perhaps it was the answer to your question, but I should have asked first whether your intention is to allow grouping/ungrouping on protected worksheets (are there others ?...). In this case, if manual handling is wanted, this solution is much neater:

Option Explicit 'Prevent typos

Private Sub Workbook_Open()
  'Work-around for Excel 97 freezing Grouping/Autofilter for protected workSHEETS
  'As these properties are not saved, this sub re-sets them at open
  'Place this at ThisWorkbook level
  Dim ws As Worksheet
  For Each ws In ActiveWorkbook.Worksheets
    With ws
     .EnableOutlining = True
     .Protect contents:=True, DrawingObjects:=True, userInterfaceOnly:=True
     .EnableAutoFilter = True
    End With
  Next ws
End Sub


Featured Post

SuperAntiSpyware Licenses Discounted by 25% !

Exclusive offer to Experts Exchange Members!
Buy SuperAntiSpyware License(s) from us and save 25% on the regular purchase price.
- Includes Full SuperAntiSpyware Vendor Support Entitlements
- Your Subscription does not begin until you activate your license
- Buy for your friends

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My experience with Windows 10 over a one year period and suggestions for smooth operation
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question