ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to return rangename of selection with VBA (https://www.excelbanter.com/excel-programming/332937-how-return-rangename-selection-vba.html)

shoba

How to return rangename of selection with VBA
 

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


Tom Ogilvy

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





All times are GMT +1. The time now is 12:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com