using named ranges in a function but range name is in a cell


Posted by steve w on August 13, 2001 8:11 PM

Maybe someone can help
I'm trying to see some text as a range name so I can use it in a formula.
Not sure if something exist already so I'm trying to make my own function.

I have some named ranges that start with the first 2 letters of the product and end with (PR)

Any ideas
Thanks steve w

Function TEXT_RANGE(TNAME) As String

TEXT_RANGE= Left(Range("TNAME"), 2)& PR

End Function

Posted by Damon Ostrander on August 13, 2001 10:09 PM

Steve,

If I understand correctly what you want to do, this is how the code should look. This assumes that the function is passed a product name (TNAME). It takes the first two characters of this product name, suffixes "PR" onto these, and then returns the text string that is contained in the cell having this four-character name.


Function TEXT_RANGE(TNAME As String) As String

TEXT_RANGE = Range(Left(TNAME & "PR"), 2)

End Function

Happy computing.

Damon



Posted by Aladin Akyurek on August 14, 2001 5:50 AM

Steve,

Just curious: Why not use

INDIRECT(LEFT(TNAME,2)&PR) [ if TNAME is a value instead of a cell ref, use double quotes around the name ]

in other formulas where you need the relevant named range, like in

=SUM(INDIRECT(LEFT(TNAME,2)&PR)) ?

Aladin

============