+ Reply to Thread
Results 1 to 8 of 8

How to make my own [user-defined function] for min value except 0

  1. #1
    Registered User
    Join Date
    10-09-2011
    Location
    Kosice, Slovakia
    MS-Off Ver
    office 365 / excel 2021
    Posts
    17

    How to make my own [user-defined function] for min value except 0

    I would like to ask you to help me to create my own formulas in VBA

    I am a purchaser and my job consist of evaluating the offers from several companies for a certain range of products. From their offers I am choosing the best prices and the supplier where to buy the particular product from that range.

    So I need to figure out :
    1) Best (Minimum)price
    2) Supplier who has the best price for the particular product.

    It is an easy formula to set up the minimum price bigger than 0 : =IFERROR(SMALL(range;COUNTIF(range;0)+1);MIN(range))
    In my table it is column C =IFERROR(SMALL(G1:J1;COUNTIF(G1:J1;0)+1);MIN(G1:J1))

    When I have minimum price I can look for the name of the company with match and index formulas. In my table it is column E =INDEX($E$2:$H$2;MATCH(C1;E1:H1;0)).

    Unfortunately, I do not know how to create my own formulas, so I do not have to think about them and write them all the times. Can somebody help me here what exsactly do I have to write to VBA module when I want to create my own formula for BESTSUPLIER and waht for BESTVALUE

    1.
    Public Function BESTVALUE()
    ...................................
    End Function


    2.
    Public Function BESTSUPLIER()
    ......................
    End Function

    Sorry for the poor description of the problem but my english is far from good but I hope you will understand what I need. I am attaching the excel file "evaluation" from which you can understand it.
    Attached Files Attached Files
    Last edited by slastanrado; 11-18-2017 at 04:29 AM. Reason: updated title to match question

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,691

    Re: How to make my own formula for min value except 0

    If you already have a formula for this that works, why do you want to write a VBA function for it?
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,810

    Re: How to make my own [user-defined function] for min value except 0

    Here's something I wrote up to describe how to put UDF's together (https://www.excelforum.com/tips-and-...uild-udfs.html ). The basics of calling but the VB editor and such are in the link given there.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Registered User
    Join Date
    10-09-2011
    Location
    Kosice, Slovakia
    MS-Off Ver
    office 365 / excel 2021
    Posts
    17

    Re: How to make my own [user-defined function] for min value except 0

    Both formulas are not exactly the easiest to remember, I have always different range of companie (sometimes 2 sometiems 10 or more )and file is more comlicated than the one I showed. There for I wanted to make my own formula where I change only variables and range.
    I edited my excel file showing the real case.

    It looks that I have to study a lot of VBA to be able to make this my own formula.

    Probably I should add this to the commercial subforum.
    Last edited by slastanrado; 11-18-2017 at 04:39 AM.

  5. #5
    Registered User
    Join Date
    10-09-2011
    Location
    Kosice, Slovakia
    MS-Off Ver
    office 365 / excel 2021
    Posts
    17

    Re: How to make my own [user-defined function] for min value except 0

    Quote Originally Posted by MrShorty View Post
    Here's something I wrote up to describe how to put UDF's together (https://www.excelforum.com/tips-and-...uild-udfs.html ). The basics of calling but the VB editor and such are in the link given there.
    Thanks for link. I will try. It is a good skill so it is worth to study.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,691

    Re: How to make my own [user-defined function] for min value except 0

    Here are two functions that do what you need, generic enough to handle any ranges.

    BESTVALUE(range) returns the lowest number greater than zero, error if no positive numbers are found

    BESTSUPPLIER(value_range, supplier_range) returns the supplier in supplier_range with the lowest corresponding value greater than zero in value_range

    Please Login or Register  to view this content.

  7. #7
    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: How to make my own [user-defined function] for min value except 0

    Here's another suggestion.

    Create a normalised two dimensional database table so that you can analyse your data simply with a Pivot Table. If you do that there's no need for functions, either Regular Excel or UDFs

    i.e create a table where each column label is a unique TYPE of data, not the value of a type of data. For instance you'd have one column for Company and in that column record the Company name, probably using a data validation drop down. Other Columns would be Pipe Size, Cost,...and whichever of columns F:P are unique TYPES, - I don't know what your data means so can't comment.
    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.

  8. #8
    Registered User
    Join Date
    10-09-2011
    Location
    Kosice, Slovakia
    MS-Off Ver
    office 365 / excel 2021
    Posts
    17

    Re: How to make my own [user-defined function] for min value except 0

    Waw. Thanks a lot. You are the BEST.

+ 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. [SOLVED] Help with advanced LEN and Substitute formula to make a special rule in formula
    By Kron in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-07-2017, 12:23 PM
  2. Replies: 6
    Last Post: 01-04-2017, 11:20 AM
  3. How to make this formula in excell sheet..please help me to make this..
    By mdinesh223 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-13-2015, 05:01 AM
  4. [SOLVED] Make formula disregard other formula entry if blank
    By DHFE in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-06-2014, 04:23 AM
  5. Alternative Formula for multiples IFs (to make my formula shorter)
    By chico.corrales in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-07-2013, 12:37 AM
  6. [SOLVED] Formula whit INDEX and MATCH. I try to make this formula to result.
    By Anka in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-28-2012, 06:26 PM
  7. Formula question - cell value to make a formula true?
    By jabadeer in forum Excel General
    Replies: 3
    Last Post: 07-19-2011, 12:07 PM

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