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
  • 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 ?????

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel 2016 - Edit Items in Custom Sort Level 5 19
Excel Calculation 4 48
populate  some cells after data verification 45 21
Transposing this formula ... 5 11
This article will show you how to use shortcut menus in the Access run-time environment.
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.
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

808 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