LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default macro to show / hide grouping, linked to label button

I’m working on macro that will expand / collapse groups. The idea is to have label buttons ‘show detail’ and ‘hide detail’ that sit above the group
You can see an example here
http://www.youtube.com/watch?v=70efsNWwuIU#t=14m00s
here’s the macro so far

Sub group_expand()
''Macro to show the details of a group

‘Find the row that the button that called the procedure is in

buttonRow = ActiveSheet.Shapes(Application.Caller).TopLeftCell .Row

'Check to see if grouping details are already showing
If Worksheets("IS").Rows(buttonRow + 1).ShowDetail = True Then
‘If grouping detail is already showing, then do nothing
Else
‘If the grouping detail is hidden, then show the detail
Worksheets("IS").Rows(buttonRow + 1).ShowDetail = True
End If
End Sub

There are a few improvements I would like to make.

1.Find the top row of the next grouping. Currently the macro is hardcoded and label has to be exactly 1 row above the top of the grouping. I can find the row location of the button, however I don’t know how to find the top row of the next group.

In other words, I’d replace the (buttonRow + 1) with (buttonRow + distance to top row of next grouping),

e.g.

If Worksheets("IS").Rows(buttonRow + 1).ShowDetail = True

To

If Worksheets("IS").Rows(buttonRow + [distance to top row of next grouping]).ShowDetail = True

2. Find the height of the grouping

Here’s where I’m up to.

ActiveSheet.Activate
Set myRange = ActiveCell.CurrentRegion
lastRow = myRange.Rows.Count

This will return the correct height of the grouping. However, I need this driven off a cell reference, not ActiveCell.


My first thought was to make the following change:

Set myRange = Cells(BR + [distance to top row of next grouping],1).CurrentRegion
lastRow = myRange.Rows.Count

But this doesn’t work. The value of lastRow is always 1 in this example.

If anyone has a better way to determine the height of a grouping I would love to hear.

3. Finally, check to see if the summary rows are at the top of the grouping or at the bottom of the grouping (i.e. does the +/- show up at the top of the grouping or at the bottom of the grouping).

As this is currently coded, the macro only works if the summary rows are set to be at the top of the grouping. If the summary row (+/- button) is at the bottom of the grouping then I need to add not 1, but the 1 + height of the grouping to the buttonRow.

I’m sure the location of the summary row/(+/-) is a property of groupings, I just don’t know what the property is.
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hide Rows or Columns with +/- button above row/column label headin WA Excel Worksheet Functions 3 April 5th 23 02:42 PM
How to show and hide a picture on a button at runtime? Mark Stephens Excel Programming 2 January 20th 09 08:23 AM
hide or show a series with a button Craig Charts and Charting in Excel 1 December 6th 07 04:36 AM
Show / Hide Label O.... Excel Programming 1 October 4th 07 07:15 PM
hide and show columns using one control button dreamkeeper Excel Programming 8 March 3rd 06 03:16 AM


All times are GMT +1. The time now is 09:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"