Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Macro to Group andor Ungroup rows and/or columns

Hello,
I'm an intermediate user of macros and VBA programing but I can't figure
this out. I want to create a macro that will identify if I have selected
rows or columns and if what I've selected is grouped or not and then either
group the selection or ungroup the selection based on these answers. This is
what I've built...obviously it doesn't work. Please help if you can.

Sub GroupUngroupSelection()

With selection
If Selection.Rows = True
If Selection.Rows.Group = True
selection.Rows.Ungroup
Else:
selection.Rows.Group
Elseif Selection.Columns = True
If Selection.Columns.Group = True
selection.Columns.Ungroup
Else:
selection.Columns.Group
End With
End Sub

--
Thanks a million,

Nick Junod
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Macro to Group andor Ungroup rows and/or columns

You need to explain what a grouped selection is.
--
Jim Cone
Portland, Oregon USA



"Nick Junod"

wrote in message
Hello,
I'm an intermediate user of macros and VBA programing but I can't figure
this out. I want to create a macro that will identify if I have selected
rows or columns and if what I've selected is grouped or not and then either
group the selection or ungroup the selection based on these answers.
This is what I've built...obviously it doesn't work. Please help if you can.

Sub GroupUngroupSelection()
With selection
If Selection.Rows = True
If Selection.Rows.Group = True
selection.Rows.Ungroup
Else:
selection.Rows.Group
Elseif Selection.Columns = True
If Selection.Columns.Group = True
selection.Columns.Ungroup
Else:
selection.Columns.Group
End With
End Sub
--
Thanks a million,
Nick Junod
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Macro to Group andor Ungroup rows and/or columns

What I mean by a grouped selection is the same thing as under the Data menu |
Group and Outline | Group.

Does that help?
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Macro to Group andor Ungroup rows and/or columns

Sub WhichWay()
Dim rng As Range
Set rng = Selection
If rng.Columns.Count = Columns.Count Then
rng.Group
MsgBox "Entire Rows Grouped" & vbCr & rng.Address
ElseIf rng.Rows.Count = Rows.Count Then
rng.Group
MsgBox "Entire Columns Grouped" & vbCr & rng.Address
Else
MsgBox "Not entire rows or columns " & vbCr & _
"However let's group rows. " & vbCr & rng.Address
rng.EntireRow.Group
MsgBox "Rows grouped for... " & vbCr & rng.Address
End If
rng.EntireRow.ClearOutline
End Sub
--
Jim Cone
Portland, Oregon USA


"Nick Junod"

wrote in message
What I mean by a grouped selection is the same thing as
under the Data menu | Group and Outline | Group.

Does that help?
Reply
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
Range.Group Method - group rows, not columns serhio[_2_] Excel Programming 1 May 7th 08 01:26 PM
Group and ungroup Danny[_12_] Excel Programming 2 November 9th 07 09:20 AM
Use VBA to find, Group, Ungroup rows donesquire Excel Programming 2 July 27th 06 03:09 PM
On protected Excel sheet users be able to group/ungroup rows/colum Oryssia Excel Worksheet Functions 2 June 6th 06 12:49 PM
how do you group and ungroup rows or columns in new Excel? moocowcreamer Excel Worksheet Functions 2 November 17th 04 02:28 AM


All times are GMT +1. The time now is 03:11 PM.

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

About Us

"It's about Microsoft Excel"