+ Reply to Thread
Results 1 to 6 of 6

UDF: Need help with creating Countif based UDF

  1. #1
    Registered User
    Join Date
    06-21-2016
    Location
    NYC
    MS-Off Ver
    2010
    Posts
    3

    UDF: Need help with creating Countif based UDF

    All,

    I am new to UDFs and need to create one for the following formula:

    =IF(COUNTIF($D2:D$20000,D2)=1,(COUNTIF(D:D,D2)/COUNTIF(D:D,D2)),"0")

    Any help would be greatly appreciated.

  2. #2
    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: UDF: Need help with creating Countif based UDF

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    will return a value of 1, and "0" is a text string, not the value 0.
    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


  3. #3
    Registered User
    Join Date
    06-21-2016
    Location
    NYC
    MS-Off Ver
    2010
    Posts
    3

    Re: UDF: Need help with creating Countif based UDF

    I understand that and it is the intended outcome. Background: I have a unique identifier which I need tagged for unique instances; my formula does that by tagging 1 or 0 (do not need value). Because my data set is growing, and the amount of unique IDs created is increasing, I need to create a UDF which will help me shorten having to write out the formula. So essentially i just want to be able to input "=uniqueinstance(d2:d20000)" or something along those lines.

  4. #4
    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: UDF: Need help with creating Countif based UDF

    What about this bit:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    The first $D2 does not have the row fixed. Is that intentional? Is D2000 meant to be fixed or do you want the UDF to determine the last row?

  5. #5
    Registered User
    Join Date
    06-21-2016
    Location
    NYC
    MS-Off Ver
    2010
    Posts
    3

    Re: UDF: Need help with creating Countif based UDF

    It is indeed intentional and ideally I would like the UDF to determine the last row; 20000 is just a placeholder at this point but the data set will exceed that in a few months time.

  6. #6
    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: UDF: Need help with creating Countif based UDF

    I think a UDF is overkill given that
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    is redundant

    You can just use this:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    And, if you create a Dynamic Named Range, for example, Col_D, defined as:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    You can then have:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Note that, when you create the DNR, you MUST be on row 2 because the row, as in $D2, will reflect the current row

    That seems pretty short to me, and much more convenient than having to make your workbook macro enabled just so you can have a UDF.

+ 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. Help creating a COUNTIF formula that will match between dates
    By relmasri in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-13-2016, 01:33 PM
  2. [SOLVED] Creating a subtotal formula with a countif
    By jakehartson in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 07-24-2014, 06:47 PM
  3. Creating dynamic userform based on several file names and creating chart overlays
    By Thorn23 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-18-2014, 12:09 PM
  4. [SOLVED] Need help in creating a COUNTIF formula based on 2 conditions
    By Manish_Gupta in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-19-2014, 11:53 AM
  5. [SOLVED] Creating a reoccuring OFFSET on a COUNTIF formula
    By excelCADfan in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-09-2013, 04:12 PM
  6. Creating a nested COUNTIF????
    By Simon Lloyd in forum Excel Formulas & Functions
    Replies: 107
    Last Post: 09-07-2005, 12:05 AM
  7. [SOLVED] Creating an EXCEL COUNTIF formula for a range of values
    By Pat Walsh in forum Excel General
    Replies: 5
    Last Post: 01-21-2005, 11:06 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