tags:

views:

1407

answers:

4

Is there a way of displaying the Cell name of a particular cell in another cell? I would like to display the cell name in the adjacent cell so that the user is able to identify the cell name without clicking it.

Thanks...

A: 

It doesn't seem to be possible, which is weird. You'd think that the cell() function should provide a way to get the name, but it doesn't. Bummer.

unwind
What if the name referenced a range? Or a formula (OFFSET, say) that happened to include the cell sometimes, but sometimes not? I think MS just declared the problem to be "too hard" and got on with something easier. ;-)
Mike Woodhouse
Good point ... I guess I'd expect to get the name that "covers" the cell, if the cell is in a named range. There could of course be other functions to help resolve any such issues, I'm surprised there aren't.
unwind
I suspect it's one of the areas where 80% don't know about the feature and of those that do, only 20% care. So there's not much pressure to come up with a solution. Much better to redesign the UI.
Mike Woodhouse
A: 

This will work in very basic circumstances:

Public Function CellName(cel As Range) As Variant
Dim nm As Name
    For Each nm In Names
        If nm.RefersTo = "=" & cel.Parent.Name & "!" & cel.Address Then
            CellName = nm.Name
            Exit Function
        End If
    Next
    CellName = CVErr(xlErrNA)
End Function

It won't work if the cell is part of a named range, it won't show multiple names for the cell, it won't work for cells included in named formulae (like =OFFSET() ranges, for example).

The

"=" & cel.Parent.Name & "!" & cel.Address

thing is pretty clunky, too. There may be a better way to do the check. Creating a Range object from the RefersTo and using Intersect() might work.

Mike Woodhouse
A: 

Excel does have a function "Cell()" that you can get certain properties from.

You can use =Cell("row", K9) and get back row number 9 and there's an equivalent "col" parameter but it returns the column number (11) rather than the letter.

jerebear
+1  A: 

This function would give the name of the NamedRange the cell belongs to:

Public Function CellName(oCell As Range) As Variant  
Dim oName As Name  
For Each oName In ThisWorkbook.Names  
    If oName.RefersToRange.Parent Is oCell.Parent Then  
        If Not Intersect(oCell, oName.RefersToRange) Is Nothing Then  
           CellName = oName.Name  
           Exit Function  
        End If  
    End If  
Next  
CellName = CVErr(xlErrNA)  
End Function

It loops through all the names in the workbook, and then for each name it checks if it refers to any thing in this the sheet input parameter is from. If it is then it checks if the input cell and the rages referred by the name intersect. If they do it returns the name of the range.

Adarsha