+ Reply to Thread
Results 1 to 4 of 4

user defined fuction not recognized / not working

  1. #1
    Registered User
    Join Date
    09-16-2009
    Location
    Arizona, USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    user defined fuction not recognized / not working

    I have Excel 2007.

    This is what I did -

    1. Pressed Alt-F11 to bring up the visual basic editor
    2. Clicked to insert a new class module
    3. Typed this code:

    Public Function colorof(ref As range)
    colorof = ref.Interior.Color
    End Function

    4. Saved file as a macro enabled workbook (.xlsm)
    5. Clicked the upper left circle thingy -> clicked Excel Options -> Trust Center -> Trust Center Settings -> Enable all macros.
    6. I also checked the box for "Trust access to the VBA project object model", although I'm not sure what that does.
    7. Went back to spreadsheet and typed this formula into A2 -

    =colorof(A1)


    After doing these steps. The value in cell A2 showed #NAME?.

    What's wrong?

  2. #2
    Registered User
    Join Date
    09-16-2009
    Location
    Arizona, USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: user defined fuction not recognized / not working

    I then went back to the visual basic editor to the class module and inserted a new procedure -

    Public Sub test()
    Debug.Print colorof(Range("A1"))
    End Sub

    then put my cursor inside and pressed F5 to try to run it. It popped up the dialog to choose a procedure to run, but the list was empty- there were no procedures to choose from.


    Is it possible our network administrators at my work disabled all our macro abilities, even though my macro security shows enabled?

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

    Re: user defined fuction not recognized / not working

    Hello ztodd,

    Welcome to the Forum!

    You placed your code in the wrong type of module. You need to cut and paste the code from the Class module into a standard VBA Module. Class modules are for creating objects. UDFs go into standard modules.
    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!)

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: user defined fuction not recognized / not working

    ztodd, please take a few minutes to read the forum rules, and then edit your post to add code tags.

    Thanks.
    Entia non sunt multiplicanda sine necessitate

+ 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