Solved

Group and Outline in Excel

Posted on 2001-06-20
7
4,496 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you ever had the experience that you had to follow 10 steps over and over again every time when you need to nicely forward an important email to your manager? Fear no more! With the help of the Quick Steps feature in Outlook 2010, your old chor…
Outlook Free & Paid Tools
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now