ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Show field or range name in a cell (https://www.excelbanter.com/excel-discussion-misc-queries/108957-show-field-range-name-cell.html)

Michael Excel Dude

Show field or range name in a cell
 
Hi. I'm trying to keep all my naming conventions documented, so I've set up a sheet in my work book listing all the cell or range names I've created.

Is there any way to have a cell show the assigned name of another cell? Can this formula be put directly in the cell

example =name($B$1)

Thanks

Dave Peterson

Show field or range name in a cell
 
Not with anything built into excel.

But you could create a userdefined function that could return that name.

Option Explicit
Function myName(rng As Range) As String
Application.Volatile True
On Error Resume Next
myName = rng.Name.Name
On Error GoTo 0
End Function

This kind of function could be one calculation behind. If the Name changes (or
gets created), then you'll want to force a recalculation before you believe the
results.

Application.volatile true
means that excel will recalculate each of these formulas each time excel
recalculates. You may notice a slowdown in your workbook.

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Short course:

Open your workbook.
Hit alt-f11 to get to the VBE (where macros/UDF's live)
hit ctrl-R to view the project explorer
Find your workbook.
should look like: VBAProject (yourfilename.xls)

right click on the project name
Insert, then Module
You should see the code window pop up on the right hand side

Paste the code in there.

Now go back to excel.
Into a test cell and type:
=myName(a1)

==========
Remember that ranges/cells can have more than one name and that a single cell
could be part of lots of ranges. So you may not get the name you expect.

If this is to help you develop a workbook (checking purposes), then don't use
this.

Get a copy of Jan Karel Pieterse's (with Charles Williams and Matthew Henson)
Name Manager:

You can find it at:
NameManager.Zip from http://www.oaltd.co.uk/mvp

If you use names, this will make you're life easier.



Michael Excel Dude wrote:

Hi. I'm trying to keep all my naming conventions documented, so I've
set up a sheet in my work book listing all the cell or range names I've
created.

Is there any way to have a cell show the assigned name of another cell?
Can this formula be put directly in the cell

example =name($B$1)

Thanks

--
Michael Excel Dude


--

Dave Peterson


All times are GMT +1. The time now is 08:44 AM.

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