Solved

Group and Outline in Excel

Posted on 2001-06-20
7
4,560 Views
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.

Peter
0
Comment
Question by:forsbom
  • 5
  • 2
7 Comments
 
LVL 13

Expert Comment

by:cri
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.
0
 
LVL 13

Expert Comment

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

Author Comment

by:forsbom
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 ?????

Peter
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Accepted Solution

by:
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

OR

b) Use the Toggle above

OR

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

OR

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
      Else
         '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
0
 
LVL 3

Author Comment

by:forsbom
ID: 6209617
Thanks cri!!
Great answer!

Peter
0
 
LVL 13

Expert Comment

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

Expert Comment

by:cri
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


0

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

No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

749 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