Refer To Named Constant In VBA

  • I created a name in Excel 2002, Name = "NameToUse", Refers to = "Bill".
    How do I get the value in VBA code?

    Code
    Range("NameToUse").value ' doesnt work
    NameToUse ' doesn't work


    What does?


    TIA

  • Re: Named Constants In Vba


    Code
    ThisWorkbook.Names("NameToUse").RefersTo


    Code tags for VBA are a cardinal rule of the forum; I've added them for you above, please be mindful in the future.

    [SIZE=1]Entia non sunt multiplicanda sine necessitate.[/SIZE]

  • Re: Refer To Named Constant In VBA


    Thanks, that helps.
    But now there's a different problem.
    The value returned always contains an "=" and quotation marks. I would like it to return just [Bill] not [="Bill"]
    I know I can strip them out, but is there a way to enter it into the Refers To so that they aren't there in the 1st place?

  • Re: Refer To Named Constant In VBA


    Code
    Dim s As String
        s = ThisWorkbook.Names("NameToUse").RefersTo
        Debug.Print Mid(s, InStr(s, """") + 1, Len(s) - InStr(s, """") - 1)


    ... or just strip them out, as you say.

    [SIZE=1]Entia non sunt multiplicanda sine necessitate.[/SIZE]

  • Re: Refer To Named Constant In VBA


    I have a related question: can a CONST refer to a cell value or named range?


    I realize this violates the idea of a CONST, because the values could change, but could it be done and would there be any value in doing so as opposed to refering to a named range within a sub() procedure?

  • Re: Refer To Named Constant In VBA


    Try hacking around with this:



    Example values for the RefersTo in the name manager:
    ="String value"
    =100.5

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!