+ Reply to Thread
Results 1 to 5 of 5

Using Defined Name/Formula result in VBA

  1. #1
    Forum Contributor CheshireCat's Avatar
    Join Date
    10-11-2011
    Location
    Victoria, Canada
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    258

    Using Defined Name/Formula result in VBA

    I have an Excel spreadsheet with several columns of data. Since the columns might be re-arranged in the future, I have defined several "Named" ranges with formulas to give me the column numbers of the data.

    e.g. The defined name "colFullName" refers to the formula:

    Please Login or Register  to view this content.
    I want to use the resulting values of the defined names/formulas in VBA, but I can't find the proper syntax to do so.

    Here's the basic test I've been trying:

    Please Login or Register  to view this content.
    I've also tried:

    Please Login or Register  to view this content.
    but it just returns an error "Type mismatch (Error 13)"

    What is the correct syntax to use the resulting value of a named formula in VBA?
    Last edited by CheshireCat; 01-09-2012 at 06:50 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Using Defined Name/Formula result in VBA

    Hello CheshireCat,

    The VBA syntax is...
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor CheshireCat's Avatar
    Join Date
    10-11-2011
    Location
    Victoria, Canada
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    258

    Re: Using Defined Name/Formula result in VBA

    Hi Leith,

    Sorry, that gives me a Run-Time Error '1004' Application-defined or object-defined error.

    Does "Range" work when there is a formula in the defined name?
    Attached Files Attached Files
    Last edited by CheshireCat; 01-09-2012 at 06:39 PM.

  4. #4
    Forum Contributor CheshireCat's Avatar
    Join Date
    10-11-2011
    Location
    Victoria, Canada
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    258

    Re: Using Defined Name/Formula result in VBA

    Okay, I'll modify my approach to use a cell reference instead of a formula in the defined name. This will allow Range to work.

    Thanks Leith.

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Using Defined Name/Formula result in VBA

    Hello ChesireCat,

    Make your named range dynamic and the VBA code will work. Here is formula for the named range "colFullName".
    =OFFSET(StaffList!D1,1,0,COUNTA(StaffList!D:D)-1,1)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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