Excel 2007 ang "Group row" option

V

Vit

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
 
O

OssieMac

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top