+ Reply to Thread
Results 1 to 8 of 8

Better way to find minimum value excluding zero and non number

  1. #1
    Registered User
    Join Date
    08-14-2011
    Location
    Jakarta, Indonesia
    MS-Off Ver
    Excel 2007
    Posts
    63

    Better way to find minimum value excluding zero and non number

    I have written this code to look for minimum value by excluding zero and non number.


    Please Login or Register  to view this content.
    Is there a better way to do so?
    Note that within the list the biggest number would be 1 thus I set the control variable at 1.1. The above code is part of my overall code, lr1 is the data length.

    Any input would be appreciated.

  2. #2
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Better way to find minimum value excluding zero and non number

    Hello,
    Here's a suggestion using a custom function that you can adapt.
    You pass a range to the function to get the minimum.
    In the example, you select a range of cells and execute the macro "test"...

    Please Login or Register  to view this content.
    GC Excel

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

  3. #3
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Better way to find minimum value excluding zero and non number

    If you have a large range with multiple cells, you can use an array to make it faster :

    Please Login or Register  to view this content.

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,697

    Re: Better way to find minimum value excluding zero and non number

    Hi,

    I do not think it works that way, in both cases function will return last non-zero numeric value, because all the time it is compared with max

    taking second function as example working way would be:

    Please Login or Register  to view this content.
    By te way: max could be bigger (double can be some 1.79 × 10^308).
    Best Regards,

    Kaper

  5. #5
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Better way to find minimum value excluding zero and non number

    @Kaper,
    Thanks for the correction...
    I answered to rapidly without testing the code...

  6. #6
    Registered User
    Join Date
    08-14-2011
    Location
    Jakarta, Indonesia
    MS-Off Ver
    Excel 2007
    Posts
    63

    Re: Better way to find minimum value excluding zero and non number

    @Kaper & GCExcel,

    Thanks for the replies. I will have a check on them soon.

    Frankly, I have never used function. I always build in sub. Is there a different? Or is a function can be called within a sub?

  7. #7
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,697

    Re: Better way to find minimum value excluding zero and non number

    well, two main ideas behind structural programming (using subs and functions) are code reusing and keeping code readable (not to mention reccursion and other benefits).

    anyway, you white the code

    Please Login or Register  to view this content.
    below your End Sub or in separate module
    and in main sub you call it just the same way you call built-in functions, so for instance:

    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    Of course you can built-in the function in your main code, but as it is already written as a function there is no real need to do it (non-structural code could execute a tiny bit faster because there could be some overhead for calling function).

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    08-14-2011
    Location
    Jakarta, Indonesia
    MS-Off Ver
    Excel 2007
    Posts
    63

    Re: Better way to find minimum value excluding zero and non number

    To all contributor,

    Thanks a lot..

+ 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] Finding the minimum value in a range but excluding one value
    By Wilgoss in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 10-04-2012, 08:39 AM
  2. Minimum value excluding zero?
    By Ritte in forum Excel - New Users/Basics
    Replies: 8
    Last Post: 12-30-2009, 05:18 PM
  3. Find minimum SUM if no minimum number in row
    By zbor in forum Excel General
    Replies: 9
    Last Post: 12-25-2009, 05:04 AM
  4. Replies: 13
    Last Post: 04-15-2009, 08:50 PM
  5. Find Minimum, excluding ties
    By Georgia Golfer in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-06-2009, 12:41 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