+ Reply to Thread
Results 1 to 11 of 11

how to find minimum of 4 variable with a condition greater than zero

  1. #1
    Forum Contributor
    Join Date
    07-10-2019
    Location
    england
    MS-Off Ver
    2013
    Posts
    486

    how to find minimum of 4 variable with a condition greater than zero

    Hi,
    I have 3 declared variable
    a=2
    b=-7
    c=9
    d=0

    In this i need a value to be considered for further calculations in the macro.
    But when i do minimum -worksheet function.min()
    not giving correct answer..
    How to go about this..
    Should i use if conditions or is there any function to find minimum positive of numbers.

  2. #2
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,082

    Re: how to find minimum of 4 variable with a condition greater than zero

    1. "I have 3 declared variable"
    a=2
    b=-7
    c=9
    d=0

    That's 4 variables.

    2. What's your actual code?
    3. What result does it give?
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  3. #3
    Forum Contributor
    Join Date
    07-10-2019
    Location
    england
    MS-Off Ver
    2013
    Posts
    486

    Re: how to find minimum of 4 variable with a condition greater than zero

    Please Login or Register  to view this content.
    In this , i have done like this..
    But i dont want this application . wrksht fun..
    I need some thing simpler and also , it works in my excel 2010 but for client it throws error 400

  4. #4
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,082

    Re: how to find minimum of 4 variable with a condition greater than zero

    You haven't described what you're trying to do.
    Do you want the minimum value entered?
    If the array is initialised to 0s
    then MIN(a()) would give 0 not the minimum data entered.

    The code looks simple but I dont know if you can do min(a()) as am not an expert on it.

  5. #5
    Forum Contributor
    Join Date
    07-10-2019
    Location
    england
    MS-Off Ver
    2013
    Posts
    486

    Re: how to find minimum of 4 variable with a condition greater than zero

    Hi,
    The values of these variables are populated as above in the first post.. I put them in array after checking greater than zero and finding minimum..
    I put them in array, to remove non zero values .. So then min function is used to check min..
    IN this , i take care of less than 0 values and zero values to be ignored.. The array of that will be empty.. so it wont affect min function..

    I want to know, whether to get minimum of values stored in a variable multiple.. it should be non negative and non zero. is there any function or any alternate checking..

    And somewhere i read, worksheet function, slows the process and it is adviced to use..

  6. #6
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,082

    Re: how to find minimum of 4 variable with a condition greater than zero

    Last edited by Special-K; 10-11-2019 at 05:28 AM.

  7. #7
    Forum Contributor
    Join Date
    07-10-2019
    Location
    england
    MS-Off Ver
    2013
    Posts
    486
    Hi,
    Thanks this is simple logic... And I went from USA to UK in my code... Thanks ..

  8. #8
    Forum Contributor
    Join Date
    07-10-2019
    Location
    england
    MS-Off Ver
    2013
    Posts
    486

    Re: how to find minimum of 4 variable with a condition greater than zero

    Hi, one doubt.. macro working in one version can cause errors in other version?

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this …


    An array starter demonstration :

    PHP Code: 
    Sub Demo1()
        
    Dim VM&, C&
            
    = [{2,-7,9,0}]
            
    Application.Max(V)
        For 
    LBound(VTo UBound(V)
            If 
    V(C) <= 0 Then V(C) = M
        Next
            Debug
    .Print Application.Min(V)
    End Sub 

    The same via a function :

    PHP Code: 
    Function MinP(ParamArray V())
         
    Dim WXC&
             
    V
             X 
    Application.Max(W)
         For 
    LBound(WTo UBound(W)
             If 
    W(C) <= 0 Then W(C) = X
         Next
             MinP 
    Application.Min(W)
    End Function

    Sub Demo2()
        
    Dim A%, B%, C%, D%
            
    2:  = -7:  9:  0
            Debug
    .Print MinP(ABCD)
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 10-11-2019 at 06:43 AM. Reason: optimization …

  10. #10
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb


    Another way :

    PHP Code: 
    Sub Demo3()
        
    Dim A%, B%, C%, D%, VL&
            
    2:  = -7:  9:  0
            V 
    VBA.Array(ABCD)
        For 
    0 To 3
            
    If V(L) = 0 Then V(L) = -1
        Next
            V 
    Filter(V"-"False)
            If 
    UBound(V) > -1 Then Debug.Print Evaluate("MIN({" Join(V",") & "})")
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  11. #11
    Forum Contributor
    Join Date
    07-10-2019
    Location
    england
    MS-Off Ver
    2013
    Posts
    486

    Re: how to find minimum of 4 variable with a condition greater than zero

    Hi all, can anybody see thread macro error 400.. and check my code , and see if there is any error..
    I have explained in detail , there.. for me the code is working fine.. but in excel 365 it is not so.. itseems.. and error 400 is showing up itseems..

+ 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] minimum vales in a row greater than zero
    By Araise in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-08-2015, 12:27 PM
  2. Find Minimum Value in Variable Range (On Separate Sheet)
    By FancyCorndog in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-12-2012, 01:42 PM
  3. How to find a minimum value with a vlookup and a condition?
    By anthonyu in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-17-2012, 06:10 PM
  4. Find minimum value with vlookup and condition
    By anthonyu in forum Excel General
    Replies: 3
    Last Post: 04-17-2012, 09:55 AM
  5. Replies: 4
    Last Post: 12-05-2011, 07:01 PM
  6. Find minimum value greater than a particular value
    By John Michl in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-27-2006, 02:15 PM
  7. minimum greater than zero
    By OkieViking in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 03-19-2006, 02:40 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