Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
hi all,
I'm working on excel 2007 and using the "group row option".... I have organised the data and use the feature to group some rows... how can I understand, from vba, if I have select the first or the last collo of the group???? thanks cheers Vit |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Vit,
Someone may have a better way of doing this and I will be interested if they do. However, this is how I would do it. Firstly on the worksheet when you select the range to group then go into named ranges and name the range eg. Group1, Group2 etc. Then in VBA you can identify those named ranges and assign them to range variables. From there you can calculate the column number within the range. (I have never been able to directly return the relative column number withing a range assigned to a variable). You may wish to use intersect in a case statement to first establish what range the selection is in. My example only uses one group. Dim rngMyRng As Range Dim firstColMyRng As Long Dim selectionCol As Long Dim selectColMyRng As Long Dim isect As Object Set rngMyRng = Range("Group1") 'following needs to be within case to establish which 'range the selection is in Set isect = Application.Intersect(Selection, rngMyRng) If isect Is Nothing Then MsgBox "No ranges intersect with selection" Exit Sub End If 'Identify the first column number of the assigned range firstColMyRng = rngMyRng.Cells(1, 1).Column 'Identify the column number of the selected cell/range selectionCol = Selection.Column 'Therefore relative column number in named range is: selectColMyRng = selectionCol - firstColMyRng + 1 Feel free to get back to me if you need more info or clarification. -- Regards, OssieMac "Vit" wrote: hi all, I'm working on excel 2007 and using the "group row option".... I have organised the data and use the feature to group some rows... how can I understand, from vba, if I have select the first or the last collo of the group???? thanks cheers Vit |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel 2007: top of screen "File Name [Group]", how to remove [Grou | Excel Discussion (Misc queries) | |||
2007 Need macro to auto set option buttons all to "Yes" or "No" | Excel Worksheet Functions | |||
Restoring "Sized with Window" option in Excel 2007? | Charts and Charting in Excel | |||
Excel 2007 "Find" option won't work. | Excel Worksheet Functions | |||
Custom Menus & "Begin a Group" option | Excel Programming |