+ Reply to Thread
Results 1 to 4 of 4

Scripting Creation of Defined Names referring to a formula

  1. #1
    Registered User
    Join Date
    07-01-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    19

    Scripting Creation of Defined Names referring to a formula

    I am currently using a formula inside of a named range to create a drop list and remove any gaps. I have a project where I need to create several hundred of these named ranges for use in drop down lists and I want to avoid having to do all of this manually in name manager. Is there a way that I can stage the attributes for the named range inside a group of cells and reference those inside of some VB to create them?

    I was thinking of staging the names of the named ranges inside of a range of cells and the formula it would refer to inside of a different range of cells.

    Here is an example of the formula I want to have the named range refer to: =Sheet1!$G$57:INDEX(Sheet1!$G$57:$G$76,COUNTIF(Sheet1!$G$57:$G$76,"*?")+COUNTIF(Sheet1!$G$57:$G$76,">1"))

  2. #2
    Registered User
    Join Date
    07-01-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Scripting Creation of Defined Names referring to a formula

    I am getting closer so maybe my progress will spawn some inspiration for someone better at this to help me finish it. I used the macro recorder to get this formula for creating the names.

    ActiveWorkbook.Names.Add Name:="NewNamedReference", RefersToR1C1:= _
    "=Sheet1!R1C1:R13C1"

    What I would like to do is have the "NewNamedReference" value be the value from a specific cell and the "=Sheet1!R1C1:R13C1" value be the FORMULA inside of the cell next to it. The final component would be having it loop this command on the next row until it ran out of rows containing data. Hopefully this description is more helpful.

  3. #3
    Registered User
    Join Date
    07-01-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Scripting Creation of Defined Names referring to a formula

    getting better with this one.

    ActiveWorkbook.Names.Add Name:=Range("A28"), RefersToR1C1:=Range("B28").FormulaR1C1

    How do I increment A28 and B28 by one until I run out of entries in column A? Setting a predetermined range would be acceptable as well.

  4. #4
    Registered User
    Join Date
    07-01-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Scripting Creation of Defined Names referring to a formula

    So here is what ended up working for me. It was a little klunky but still saved me some time.


    Dim X As Integer, Row As Integer
    Row = 28 'here I set the first row that contained my staged data.
    For X = 28 To 207 'here is the range for the total number of rows that needed to be converted into names


    ActiveWorkbook.Names.Add Name:=Range("A" & Row), RefersToR1C1:=Range("B" & Row).FormulaR1C1
    'The "A"&Row cell contained the name used to create the defined name and the "B"&Row are the cells that contained the formula inside of the cell.

    Row = Row + 1

    Next X

    There may have been a more elegant method of writing this but it got the job done. Hope it helps someone else.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Serial number creation / pre-defined alphanumeric sequence / formula
    By beano129 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-08-2012, 02:27 AM
  2. Replies: 1
    Last Post: 05-14-2012, 10:14 AM
  3. Replies: 3
    Last Post: 02-11-2012, 08:34 AM
  4. Defined names referring to nonexistent range won't pick up once existing
    By nofzinger in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-18-2010, 11:12 AM
  5. Referring to defined names from cell contents
    By Cheeky Charlie in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-06-2008, 10:27 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1