How to return rangename of selection with VBA

S

shoba

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
 

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