• Range Names

    • This topic has 3 replies, 2 voices, and was last updated 24 years ago.
    Author
    Topic
    #355618

    How can I create a Worksheet Level Range Name in Excel in VBA? In Excel itself you need to add ‘!’ before the range name, such as Name: Data RefersTo: =!A1:D4. How can I do this in programming? Cheers, Andy.

    Viewing 0 reply threads
    Author
    Replies
    • #524823

      Try something like :

      	ActiveWorkbook.Names.Add Name:="Test", RefersTo:="=Sheet1!A1:D4"

      which should name the Range A1:D4 as Test.

      Hope that is of assistance

      Andrew

      • #524828

        Thank you for your prompt reply.
        However, I wish to create a range name that doesn’t refer to a specific sheet. In Excel you can use RefersTo: =!$A$1:$D$4 (without a sheet reference). Typing the range name in the name box and pressing Enter selects A1:D4 for whichever sheet you happen to be in. However, trying to do the same in VBA generates an error.

        • #524832

          Sorry about that, but try the following :

          	    ActiveWorkbook.Names.Add Name:="TEST", RefersToR1C1:="=!R1C1:R4C4"

          I think that might give you what you want

          Andrew

    Viewing 0 reply threads
    Reply To: Range Names

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: