View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default How to return rangename of selection with VBA

I would suspect that is as good as any.

--
Regards,
Tom Ogilvy


"shoba" wrote in
message ...

I'm looking for the most efficient way to return the first rangename
which includes the current selection. And the current selection can be
a single cell.

At the moment, I'm using this routine:
-Function GetRangename(ByVal SelRng As Range) As String
On Error Resume Next
Dim nme As name
For Each nme In ThisWorkbook.Names
If Union(Range(nme), SelRng) = Range(nme) Then
GetRangename = nme
Exit Function
End If
Next nme
End Function-

As far as I know, there's no direct VBA object that returns the first
rangename which includes the cell you selected. And if I have to return
multiple rangenames, the routine needs to go through all existing
rangenames again...

Anyone got any more efficient way?

Regards,
shoba


--
shoba
------------------------------------------------------------------------
shoba's Profile:

http://www.excelforum.com/member.php...o&userid=24676
View this thread: http://www.excelforum.com/showthread...hreadid=382505