+ Reply to Thread
Results 1 to 11 of 11

Referencing a UDF in Range.Formula Property - NAME#? Error???

  1. #1
    Registered User
    Join Date
    12-10-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    39

    Exclamation Referencing a UDF in Range.Formula Property - NAME#? Error???

    Hi,

    I'm trying to reference a UDF I've built in the .Formula property (within VBA), but it keeps giving me the NAME#? error! This is how I'm trying to reference it:

    Worksheets(1).Range("AG2").Formula = "=MyUDF(A2,K2,1)"

    Edit: Corrected typo!

    If I use the UDF directly from the cell, it works fine, but I need to be able to put the formula directly into the cell via VBA.


    Any ideas? Thanks!
    Last edited by ilsley_excel; 02-08-2016 at 07:36 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    419

    Re: Referencing a UDF in Range.Formula Property - NAME#? Error???

    Hi - it has nothing to do with your UDF. Change

    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    and then it should work.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Referencing a UDF in Range.Formula Property - NAME#? Error???

    Range is not a property of the workbook, it is a property of the worksheet.

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Referencing a UDF in Range.Formula Property - NAME#? Error???

    Hi,

    Have you considered holding the UDF formula in a named cell somewhere and in VBA copy that cell to your AG2 cell?
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Referencing a UDF in Range.Formula Property - NAME#? Error???

    @Richard: we don't know what the UDF does, do we? I just made something up to demonstrate the solution.

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Referencing a UDF in Range.Formula Property - NAME#? Error???

    @Trevor

    No we don't. Like you I created a test UDF =MyUDF(B1,C1) in A1

    Then in VBA say

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    which would then evaluate numbers in B10 & C10.

    ...or am I missing some subtlety here?

    Incidentally on the other little local 'difficulty' with LJLA now up to 10 months and counting

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Referencing a UDF in Range.Formula Property - NAME#? Error???

    Incidentally on the other little local 'difficulty' with LJLA now up to 10 months and counting
    I never, ever, heard anything back from VCS or POPLA. Program (repeated) on the BBC the other day, Rip Off Britain, featured this issue but it was a bit of a waste of time and seemed, if anything, to side with LJLS/VCS.

  8. #8
    Registered User
    Join Date
    12-10-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    39

    Re: Referencing a UDF in Range.Formula Property - NAME#? Error???

    Quote Originally Posted by mgs73 View Post
    Hi - it has nothing to do with your UDF. Change

    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    and then it should work.

    Sorry, that was a typo... I was rushing when I posted this earlier! It does actually say Worksheets(1).Range in my code but it still gives me the same #NAME? Error.

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Referencing a UDF in Range.Formula Property - NAME#? Error???

    Think you need to post a sample workbook that demonstrates the problem.

  10. #10
    Registered User
    Join Date
    12-10-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    39

    Re: Referencing a UDF in Range.Formula Property - NAME#? Error???

    Quote Originally Posted by TMS View Post
    Think you need to post a sample workbook that demonstrates the problem.
    Sorry for the delayed response. I managed to sort it out earlier, but thanks to everyone who posted!

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Referencing a UDF in Range.Formula Property - NAME#? Error???

    You're welcome. Thanks for the rep.


    Care to share what the problem was and what you did to sort it out?


    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ 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. Error 1004 Hidden Property of Range Class???
    By dgibney in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-23-2015, 11:56 AM
  2. [SOLVED] Getting --unable to get the findnext property of the range class ERROR
    By DeanJS in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-10-2014, 11:38 AM
  3. VBA error - Unble to set the Locked property of the Range class
    By Libster78 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-01-2013, 04:16 PM
  4. [SOLVED] .formula property referencing a defined string constant
    By cwkoops in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-25-2012, 09:44 AM
  5. unable to set FormulaArray property of Range Class Error
    By BuglerX in forum Access Programming / VBA / Macros
    Replies: 1
    Last Post: 11-23-2011, 01:13 PM
  6. unable to set FormulaArray property of Range class Error
    By BuglerX in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-23-2011, 12:14 PM
  7. Error: Cannot Set Range Class Property
    By 2hOt in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-01-2006, 07:55 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