• Simple utility macro to define range name

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Simple utility macro to define range name

    Author
    Topic
    #459506

    I regularly use a Defined Range name DATA that I have to create manually. I’m trying to create a macro in Personal.xls to be attached to a button, that will do this for me. The below does not work. It bombs at the last line, and when I look in my test workbook, I do not see the range name as having been created anyway. It shows it defined for a Personal.xls sheet and cell! TYIA.
    Sub DefineDATA()

    ‘ DefineDATA Macro
    ‘ Range(“A1″).Select
    ActiveWorkbook.Names.Add Name:=”DATA”, RefersToR1C1:= _
    “=OFFSET(Data!R1C1,0,0,COUNTA(Data!C1),COUNTA(Data!R1))”
    Application.Goto Reference:=”DATA”
    End Sub

    Viewing 2 reply threads
    Author
    Replies
    • #1158754

      Your code works correctly for me: it creates the name and selects the range it refers to.

      I’d quit and restart Excel and try it again; hopefully it’ll work then.

    • #1158770

      It will fail if you have no data in either Row 1 or Column 1 of Sheet(“Data”) when you run it.

    • #1158823

      Thanks. I neglected to rename Sheet1 to DATA. Now the macro starts off by renaming the active sheet DATA and it works.

    Viewing 2 reply threads
    Reply To: Simple utility macro to define range name

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

    Your information: