+ Reply to Thread
Results 1 to 14 of 14

Excel 2016-Custom Function not available to use in-cell

Hybrid View

  1. #1
    Registered User
    Join Date
    01-24-2018
    Location
    UK
    MS-Off Ver
    2010
    Posts
    6

    Excel 2016-Custom Function not available to use in-cell

    I am trying to create a custom function (to count the number of cells in a range that have font color = red). I have the code to do this, so that's not my problem. My problem is that having created the function, saved the VBA screen when I go back to the spreadsheet and type "=countcolorif(" the function is just not in the list and if I persist in trying to complete the syntax, I just get "#NAME" error. What's going on?

    I googled this a lot and watched YouTube videos but the function still refuses to show in-cell. It is in the user-defined list when I select "Insert Function" on the Formulas ribbon but I do not want to access it from there. I just want to type into the cell itself.

    1. Excel version is Microsoft Office pro 2016
    2. The function is prefaced with "Public"
    3. The vba is located in a new module not in "ThisWorkbook" area.

    Code is:

    Public Function CountColorIf(rSample As Range, rArea As Range) As Long
        Dim rAreaCell As Range
        Dim lMatchColor As Long
        Dim lCounter As Long
    
        lMatchColor = rSample.Interior.Color
        For Each rAreaCell In rArea
            If rAreaCell.Interior.Color = lMatchColor Then
                lCounter = lCounter + 1
            End If
        Next rAreaCell
        CountColorIf = lCounter
    End Function
    What on earth am I doing wrong?

    Thanks
    Last edited by Pepe Le Mokko; 02-05-2019 at 07:37 AM. Reason: Added code tags

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,984

    Re: Excel 2016-Custom Function not available to use in-cell

    Perhaps macros are disabled?
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    01-24-2018
    Location
    UK
    MS-Off Ver
    2010
    Posts
    6

    Re: Excel 2016-Custom Function not available to use in-cell

    Hi Rory,

    I forgot to mention that I have checked the Trust Center and macros are enabled and code project is trusted

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Excel 2016-Custom Function not available to use in-cell

    I think at this point, you need to upload your workbook and we can see where things have gone wrong

  5. #5
    Registered User
    Join Date
    01-24-2018
    Location
    UK
    MS-Off Ver
    2010
    Posts
    6

    Re: Excel 2016-Custom Function not available to use in-cell

    Hi Kyle123,

    Sample spreadsheet attached as requested.

    I think the issue was with the "XLSM" file type. The function now shows up in the "autocomplete" list.
    My problem now is that the result is still "#NAME".

    The code looks reasonable (I cut n pasted it from a webpage) but clearly does not work.

  6. #6
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,494

    Re: Excel 2016-Custom Function not available to use in-cell

    I copied and pasted the code into my excel 2016 and it works as described.. so the code is ok.

    At the risk of (also) kicking down an open door... but I think better to exclude
    Are you by any chance testing / trying to use this function in the Online version (in browser) of excel?
    as (most) vba will not work in online versions

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,333

    Re: Excel 2016-Custom Function not available to use in-cell

    Did you put the code in a standard module ?
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  8. #8
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,611

    Re: Excel 2016-Custom Function not available to use in-cell

    Your post does not comply with Rule 2 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    As you are new here I will add them for you this time

  9. #9
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Excel 2016-Custom Function not available to use in-cell

    Change the name of your module so that it isn't the same as the name of the function, or fully qualify it like this:
    =CountColorIf.CountColorIf(B3,D3:D8)

  10. #10
    Registered User
    Join Date
    01-24-2018
    Location
    UK
    MS-Off Ver
    2010
    Posts
    6

    Re: Excel 2016-Custom Function not available to use in-cell

    Thanks Kyle - good catch. The formula now resolves...but it says "6" on the sheet rather than the 2 expected. Lol - I'll try and debug the code

  11. #11
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,494

    Re: Excel 2016-Custom Function not available to use in-cell


    rSample.Interior.Color
    will only catch the cell fill color if you want ot test for font color you need to use rSample.Font.Color

    (also change rAreaCell ofcourse

  12. #12
    Registered User
    Join Date
    01-24-2018
    Location
    UK
    MS-Off Ver
    2010
    Posts
    6

    Re: Excel 2016-Custom Function not available to use in-cell

    Hi Roel,

    Yep that's the answer. All works now.Thanks.

    And thanks to everyone for spending their time looking at this - I've only just joined the forum and got an avalanche of replies. Totally awesome

  13. #13
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,611

    Re: Excel 2016-Custom Function not available to use in-cell

    Please acknowledge post #7. Thank you

  14. #14
    Registered User
    Join Date
    01-24-2018
    Location
    UK
    MS-Off Ver
    2010
    Posts
    6

    Re: Excel 2016-Custom Function not available to use in-cell

    My apologies Pepe - post #7 acknowledged

+ 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. How to pass named arguments to custom (UDF) functions in Excel 2016
    By Cornan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-18-2019, 11:12 AM
  2. [SOLVED] Excel 2016 Custom formatting 18/04 YY/MM
    By clairh2011 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-04-2018, 10:04 AM
  3. Replies: 1
    Last Post: 09-18-2017, 08:27 AM
  4. Custom Globe (3d Maps Excel 2016)
    By Skagyeix in forum Excel General
    Replies: 0
    Last Post: 04-05-2017, 06:04 AM
  5. Had custom toolbar in older Excel for Mac, seeking similar functionality in Excel 2016
    By ianpage in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 2
    Last Post: 05-13-2016, 11:06 AM
  6. Why won't Excel 2016 display my custom ribbon?
    By rkjudy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-05-2015, 04:20 PM
  7. How do you insert a custom function into an excel cell using vba?
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-06-2011, 10: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